Safe Haskell | None |
---|---|
Language | Haskell98 |
BasicPrelude mostly re-exports several key libraries in their entirety. The exception is Data.List, where various functions are replaced by similar versions that are either generalized, operate on Text, or are implemented strictly.
- module CorePrelude
- module Data.List
- module Control.Monad
- map :: Functor f => (a -> b) -> f a -> f b
- empty :: Monoid w => w
- (++) :: Monoid w => w -> w -> w
- concat :: Monoid w => [w] -> w
- intercalate :: Monoid w => w -> [w] -> w
- sum :: Num a => [a] -> a
- product :: Num a => [a] -> a
- show :: Show a => a -> Text
- read :: Read a => Text -> a
- readIO :: Read a => Text -> IO a
- readFile :: FilePath -> IO Text
- writeFile :: FilePath -> Text -> IO ()
- appendFile :: FilePath -> Text -> IO ()
- lines :: Text -> [Text]
- words :: Text -> [Text]
- unlines :: [Text] -> Text
- unwords :: [Text] -> Text
- textToString :: Text -> String
- ltextToString :: LText -> String
- encodeUtf8 :: Text -> ByteString
- decodeUtf8 :: ByteString -> Text
- getLine :: IO Text
- getContents :: IO Text
- interact :: (Text -> Text) -> IO ()
- gcd :: Integral a => a -> a -> a
- lcm :: Integral a => a -> a -> a
- type ShowS = String -> String
- showsPrec :: Show a => Int -> a -> ShowS
- showList :: Show a => [a] -> ShowS
- shows :: Show a => a -> ShowS
- showChar :: Char -> ShowS
- showString :: String -> ShowS
- showParen :: Bool -> ShowS -> ShowS
- type ReadS a = String -> [(a, String)]
- readsPrec :: Read a => Int -> ReadS a
- readList :: Read a => ReadS [a]
- reads :: Read a => ReadS a
- readParen :: Bool -> ReadS a -> ReadS a
- lex :: ReadS String
- readMay :: Read a => Text -> Maybe a
- putChar :: Char -> IO ()
- getChar :: IO Char
- readLn :: Read a => IO a
Module exports
module CorePrelude
module Data.List
module Control.Monad
Enhanced exports
Simpler name for a typeclassed operation
intercalate :: Monoid w => w -> [w] -> w Source
intercalate = mconcat .: intersperse
Strict implementation
Text for Read and Show operations
readIO :: Read a => Text -> IO a Source
The readIO function is similar to read except that it signals parse failure to the IO monad instead of terminating the program.
FilePath for file operations
readFile :: FilePath -> IO Text Source
Read a file and return the contents of the file as Text. The entire file is read strictly.
writeFile :: FilePath -> Text -> IO () Source
Write Text to a file. The file is truncated to zero length before writing begins.
appendFile :: FilePath -> Text -> IO () Source
Write Text to the end of a file.
Text exports
Text operations (Pure)
textToString :: Text -> String Source
ltextToString :: LText -> String Source
encodeUtf8 :: Text -> ByteString
decodeUtf8 :: ByteString -> Text Source
Note that this is not the standard Data.Text.Encoding.decodeUtf8
. That
function will throw impure exceptions on any decoding errors. This function
instead uses decodeLenient
.
Text operations (IO)
getContents :: IO Text
Miscellaneous prelude re-exports
Math
gcd :: Integral a => a -> a -> a
is the non-negative factor of both gcd
x yx
and y
of which
every common factor of x
and y
is also a factor; for example
, gcd
4 2 = 2
, gcd
(-4) 6 = 2
= gcd
0 44
.
= gcd
0 00
.
(That is, the common divisor that is "greatest" in the divisibility
preordering.)
Note: Since for signed fixed-width integer types,
,
the result may be negative if one of the arguments is abs
minBound
< 0
(and
necessarily is if the other is minBound
0
or
) for such types.minBound
Show and Read
:: Show a | |
=> Int | the operator precedence of the enclosing
context (a number from |
-> a | the value to be converted to a |
-> ShowS |
utility function converting a Char
to a show function that
simply prepends the character unchanged.
showString :: String -> ShowS
utility function converting a String
to a show function that
simply prepends the string unchanged.
:: Read a | |
=> Int | the operator precedence of the enclosing
context (a number from |
-> ReadS a |
attempts to parse a value from the front of the string, returning a list of (parsed value, remaining string) pairs. If there is no successful parse, the returned list is empty.
Derived instances of Read
and Show
satisfy the following:
That is, readsPrec
parses the string produced by
showsPrec
, and delivers the value that
showsPrec
started with.
The lex
function reads a single lexeme from the input, discarding
initial white space, and returning the characters that constitute the
lexeme. If the input string contains only white space, lex
returns a
single successful `lexeme' consisting of the empty string. (Thus
.) If there is no legal lexeme at the
beginning of the input string, lex
"" = [("","")]lex
fails (i.e. returns []
).
This lexer is not completely faithful to the Haskell lexical syntax in the following respects:
- Qualified names are not handled properly
- Octal and hexadecimal numerics are not recognized as a single token
- Comments are not treated properly