basic-prelude-0.3.10: An enhanced core prelude; a common foundation for alternate preludes.

Safe HaskellNone

BasicPrelude

Contents

Description

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.

Synopsis

Module exports

Enhanced exports

Simpler name for a typeclassed operation

map :: Functor f => (a -> b) -> f a -> f bSource

 map = fmap

empty :: Monoid w => wSource

 empty = mempty

(++) :: Monoid w => w -> w -> wSource

 (++) = mappend

concat :: Monoid w => [w] -> wSource

 concat = mconcat

intercalate :: Monoid w => w -> [w] -> wSource

 intercalate = mconcat .: intersperse

Strict implementation

sum :: Num a => [a] -> aSource

Compute the sum of a finite list of numbers.

product :: Num a => [a] -> aSource

Compute the product of a finite list of numbers.

Text for Read and Show operations

show :: Show a => a -> TextSource

Convert a value to readable Text

read :: Read a => Text -> aSource

Parse Text to a value

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.

appendFile :: FilePath -> Text -> IO ()Source

Write Text to the end of a file.

Text exports

Text operations (Pure)

lines :: Text -> [Text]

O(n) Breaks a Text up into a list of Texts at newline Chars. The resulting strings do not contain newlines.

words :: Text -> [Text]

O(n) Breaks a Text up into a list of words, delimited by Chars representing white space.

unlines :: [Text] -> Text

O(n) Joins lines, after appending a terminating newline to each.

unwords :: [Text] -> Text

O(n) Joins words using single space characters.

encodeUtf8 :: Text -> ByteString

Encode text using UTF-8 encoding.

decodeUtf8 :: ByteString -> TextSource

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)

getLine :: IO Text

Read a single line of user input from stdin.

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

lcm :: Integral a => a -> a -> a

Show and Read

type ShowS = String -> String

showsPrec :: Show a => Int -> a -> ShowS

showList :: Show a => [a] -> ShowS

shows :: Show a => a -> 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

IO operations

putChar :: Char -> IO ()

readLn :: Read a => IO a