Safe Haskell | None |
---|
Data.String.Like
- class StringLike a where
- fromLazyText :: Text -> a
- class ToString a where
- string :: (ToString a, StringLike b) => a -> b
- text :: ToString a => a -> Text
- ltext :: ToString a => a -> Text
- bs :: ToString a => a -> ByteString
- lbs :: ToString a => a -> ByteString
- readFile :: FilePath -> IO String
- writeFile :: FilePath -> String -> IO ()
- appendFile :: FilePath -> String -> IO ()
Documentation
class StringLike a whereSource
This type class can be used to transform any string like from
lazy Text
, there is no default implementation for String
consciously,
beacause we don't want to incite String
using.
Methods
fromLazyText :: Text -> aSource
This type class can be used to transform any type to StringLike
type.
Minimal complete definition: toText
.
string :: (ToString a, StringLike b) => a -> bSource
Transform any ToString
type to any StringLike
type, it can be inferred
or should be explicitly defined.
bs :: ToString a => a -> ByteStringSource
Transform any ToString
type to strict ByteString
lbs :: ToString a => a -> ByteStringSource
Transform any ToString
type to lazy ByteString
readFile :: FilePath -> IO String
The readFile
function reads a file and
returns the contents of the file as a string.
The file is read lazily, on demand, as with getContents
.
writeFile :: FilePath -> String -> IO ()
The computation writeFile
file str
function writes the string str
,
to the file file
.
appendFile :: FilePath -> String -> IO ()
The computation appendFile
file str
function appends the string str
,
to the file file
.
Note that writeFile
and appendFile
write a literal string
to a file. To write a value of any printable type, as with print
,
use the show
function to convert the value to a string first.
main = appendFile "squares" (show [(x,x*x) | x <- [0,0.1..2]])