Safe Haskell | Safe-Infered |
---|
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
- 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
- intercalate :: Text -> [Text] -> Text
- putStr :: Text -> IO ()
- getLine :: IO Text
- getContents :: IO Text
- interact :: (Text -> Text) -> IO ()
- gcd :: Integral a => a -> a -> a
- lcm :: Integral a => a -> a -> a
- type String = [Char]
- 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
- putChar :: Char -> IO ()
- getChar :: IO Char
- readLn :: Read a => IO a
- type IOError = IOException
- ioError :: IOError -> IO a
- userError :: String -> IOError
Module exports
module CorePrelude
module Data.List
module Control.Monad
Enhanced exports
Simpler name for a typeclassed operation
Strict implementation
Text for Read and Show operations
readIO :: Read a => Text -> IO aSource
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 TextSource
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.
Text exports
Text operations (Pure)
intercalate :: Text -> [Text] -> Text
O(n) The intercalate
function takes a Text
and a list of
Text
s and concatenates the list after interspersing the first
argument between each element of the list.
Text operations (IO)
getContents :: IO Text
Lazily read all user input on stdin
as a single string.
interact :: (Text -> Text) -> IO ()
The interact
function takes a function of type Text -> Text
as its argument. The entire input from the standard input device is
passed (lazily) to this function as its argument, and the resulting
string is output on the standard output device.
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
IO operations
Exceptions
type IOError = IOException
The Haskell 98 type for exceptions in the IO
monad.
Any I/O operation may raise an IOError
instead of returning a result.
For a more general type of exception, including also those that arise
in pure code, see Control.Exception.Exception.
In Haskell 98, this is an opaque type.