Safe Haskell | None |
---|
- module CorePrelude
- undefined :: a
- (++) :: Monoid m => m -> m -> m
- class Semigroup a where
- data WrappedMonoid m
- module Control.Monad
- module Control.Concurrent.MVar.Lifted
- module Data.IORef.Lifted
- trace :: String -> a -> a
- traceShow :: Show a => a -> b -> b
- traceId :: String -> String
- traceM :: Monad m => String -> m ()
- traceShowId :: Show a => a -> a
- traceShowM :: (Show a, Monad m) => a -> m ()
- assert :: Bool -> a -> a
- module Data.Time
- defaultTimeLocale :: TimeLocale
- module Data.Foldable
- module Data.Traversable
- module Data.MonoTraversable
- module Data.Sequences
- module Data.Sequences.Lazy
- module Data.Textual.Encoding
- module Data.Containers
- data Handle
- stdin :: Handle
- stdout :: Handle
- stderr :: Handle
- map :: Functor f => (a -> b) -> f a -> f b
- concat :: (MonoFoldable c, Monoid (Element c)) => c -> Element c
- concatMap :: (Monoid m, MonoFoldable c) => (Element c -> m) -> c -> m
- length :: MonoFoldable c => c -> Int
- null :: MonoFoldable c => c -> Bool
- pack :: IsSequence c => [Element c] -> c
- unpack :: MonoFoldable c => c -> [Element c]
- repack :: (MonoFoldable a, IsSequence b, Element a ~ Element b) => a -> b
- toList :: MonoFoldable c => c -> [Element c]
- mapM :: Traversable t => forall a m b. Monad m => (a -> m b) -> t a -> m (t b)
- mapM_ :: (Monad m, MonoFoldable c) => (Element c -> m a) -> c -> m ()
- forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
- forM_ :: (Monad m, MonoFoldable c) => c -> (Element c -> m a) -> m ()
- any :: MonoFoldable c => (Element c -> Bool) -> c -> Bool
- all :: MonoFoldable c => (Element c -> Bool) -> c -> Bool
- foldl' :: MonoFoldable c => (a -> Element c -> a) -> a -> c -> a
- foldr :: MonoFoldable c => (Element c -> b -> b) -> b -> c -> b
- foldM :: (Monad m, MonoFoldable c) => (a -> Element c -> m a) -> a -> c -> m a
- readMay :: (Element c ~ Char, MonoFoldable c, Read a) => c -> Maybe a
- intercalate :: (Monoid (Element c), IsSequence c) => Element c -> c -> Element c
- zip :: Zip f => f a -> f b -> f (a, b)
- zip3 :: Zip3 f => f a -> f b -> f c -> f (a, b, c)
- zip4 :: Zip4 f => f a -> f b -> f c -> f d -> f (a, b, c, d)
- zip5 :: Zip5 f => f a -> f b -> f c -> f d -> f e -> f (a, b, c, d, e)
- zip6 :: Zip6 f => f a -> f b -> f c -> f d -> f e -> f g -> f (a, b, c, d, e, g)
- zip7 :: Zip7 f => f a -> f b -> f c -> f d -> f e -> f g -> f h -> f (a, b, c, d, e, g, h)
- unzip :: Zip f => f (a, b) -> (f a, f b)
- unzip3 :: Zip3 f => f (a, b, c) -> (f a, f b, f c)
- unzip4 :: Zip4 f => f (a, b, c, d) -> (f a, f b, f c, f d)
- unzip5 :: Zip5 f => f (a, b, c, d, e) -> (f a, f b, f c, f d, f e)
- unzip6 :: Zip6 f => f (a, b, c, d, e, g) -> (f a, f b, f c, f d, f e, f g)
- unzip7 :: Zip7 f => f (a, b, c, d, e, g, h) -> (f a, f b, f c, f d, f e, f g, f h)
- zipWith :: Zip f => (a -> b -> c) -> f a -> f b -> f c
- zipWith3 :: Zip3 f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- zipWith4 :: Zip4 f => (a -> b -> c -> d -> e) -> f a -> f b -> f c -> f d -> f e
- zipWith5 :: Zip5 f => (a -> b -> c -> d -> e -> g) -> f a -> f b -> f c -> f d -> f e -> f g
- zipWith6 :: Zip6 f => (a -> b -> c -> d -> e -> g -> h) -> f a -> f b -> f c -> f d -> f e -> f g -> f h
- zipWith7 :: Zip7 f => (a -> b -> c -> d -> e -> g -> h -> i) -> f a -> f b -> f c -> f d -> f e -> f g -> f h -> f i
- hashNub :: (Hashable a, Eq a) => [a] -> [a]
- ordNub :: Ord a => [a] -> [a]
- ordNubBy :: Ord b => (a -> b) -> (a -> a -> Bool) -> [a] -> [a]
- sortWith :: (Ord a, IsSequence c) => (Element c -> a) -> c -> c
- compareLength :: (Integral i, MonoFoldable c) => c -> i -> Ordering
- sum :: (MonoFoldable c, Num (Element c)) => c -> Element c
- product :: (MonoFoldable c, Num (Element c)) => c -> Element c
- repeat :: a -> [a]
- (\\) :: SetContainer a => a -> a -> a
- intersect :: SetContainer a => a -> a -> a
- unions :: (MonoFoldable c, SetContainer (Element c)) => c -> Element c
- class Show a where
- tshow :: Show a => a -> Text
- tlshow :: Show a => a -> LText
- charToLower :: Char -> Char
- charToUpper :: Char -> Char
- class IsSequence a => IOData a where
- readFile :: MonadIO m => FilePath -> m a
- writeFile :: MonadIO m => FilePath -> a -> m ()
- getLine :: MonadIO m => m a
- hGetContents :: MonadIO m => Handle -> m a
- hGetLine :: MonadIO m => Handle -> m a
- hPut :: MonadIO m => Handle -> a -> m ()
- hPutStrLn :: MonadIO m => Handle -> a -> m ()
- hGetChunk :: MonadIO m => Handle -> m a
- print :: (Show a, MonadIO m) => a -> m ()
- hClose :: Handle -> IO ()
- fpToString :: FilePath -> String
- fpFromString :: String -> FilePath
- fpToText :: FilePath -> Text
- fpFromText :: Text -> FilePath
- catchAny :: MonadBaseControl IO m => m a -> (SomeException -> m a) -> m a
- handleAny :: MonadBaseControl IO m => (SomeException -> m a) -> m a -> m a
- tryAny :: MonadBaseControl IO m => m a -> m (Either SomeException a)
- catchAnyDeep :: (NFData a, MonadBaseControl IO m) => m a -> (SomeException -> m a) -> m a
- handleAnyDeep :: (NFData a, MonadBaseControl IO m) => (SomeException -> m a) -> m a -> m a
- tryAnyDeep :: (NFData a, MonadBaseControl IO m) => m a -> m (Either SomeException a)
- catchIO :: MonadBaseControl IO m => m a -> (IOException -> m a) -> m a
- handleIO :: MonadBaseControl IO m => (IOException -> m a) -> m a -> m a
- tryIO :: MonadBaseControl IO m => m a -> m (Either IOException a)
- asByteString :: ByteString -> ByteString
- asLByteString :: LByteString -> LByteString
- asHashMap :: HashMap k v -> HashMap k v
- asHashSet :: HashSet a -> HashSet a
- asText :: Text -> Text
- asLText :: LText -> LText
- asList :: [a] -> [a]
- asMap :: Map k v -> Map k v
- asMaybe :: Maybe a -> Maybe a
- asSet :: Set a -> Set a
- asVector :: Vector a -> Vector a
- asUVector :: UVector a -> UVector a
- asIOException :: IOException -> IOException
- asSomeException :: SomeException -> SomeException
CorePrelude
module CorePrelude
Deprecated: It is highly recommended that you either avoid partial functions or provide meaningful error messages
We define our own undefined
which is marked as deprecated. This makes it
useful to use during development, but let's you more easily getting
notification if you accidentally ship partial code in production.
The classy prelude recommendation for when you need to really have a partial
function in production is to use error
with a very descriptive message so
that, in case an exception is thrown, you get more information than
Prelude.undefined
.
Since 0.5.5
Standard
Monoid
Semigroup
class Semigroup a where
(<>) :: a -> a -> a
An associative operation.
(a <> b) <> c = a <> (b <> c)
If a
is also a Monoid
we further require
(<>) = mappend
Reduce a non-empty list with <>
The default definition should be sufficient, but this can be overridden for efficiency.
times1p :: Whole n => n -> a -> a
Repeat a value (n + 1) times.
times1p n a = a <> a <> ... <> a -- using <> n times
The default definition uses peasant multiplication, exploiting associativity to only
require O(log n) uses of <>
.
See also times
.
data WrappedMonoid m
Provide a Semigroup for an arbitrary Monoid.
Typeable1 WrappedMonoid | |
Bounded m => Bounded (WrappedMonoid m) | |
Eq m => Eq (WrappedMonoid m) | |
Data m => Data (WrappedMonoid m) | |
Ord m => Ord (WrappedMonoid m) | |
Read m => Read (WrappedMonoid m) | |
Show m => Show (WrappedMonoid m) | |
Monoid m => Monoid (WrappedMonoid m) | |
Monoid m => Semigroup (WrappedMonoid m) |
Monad
module Control.Monad
Mutable references
module Data.IORef.Lifted
Debugging
The trace
function outputs the trace message given as its first argument,
before returning the second argument as its result.
For example, this returns the value of f x
but first outputs the message.
trace ("calling f with x = " ++ show x) (f x)
The trace
function should only be used for debugging, or for monitoring
execution. The function is not referentially transparent: its type indicates
that it is a pure function but it has the side effect of outputting the
trace message.
traceShowId :: Show a => a -> aSource
Since 0.5.9
traceShowM :: (Show a, Monad m) => a -> m ()Source
Since 0.5.9
If the first argument evaluates to True
, then the result is the
second argument. Otherwise an AssertionFailed
exception is raised,
containing a String
with the source file and line number of the
call to assert
.
Assertions can normally be turned on or off with a compiler flag
(for GHC, assertions are normally on unless optimisation is turned on
with -O
or the -fignore-asserts
option is given). When assertions are turned off, the first
argument to assert
is ignored, and the second argument is
returned as the result.
Time (since 0.6.1)
module Data.Time
Poly hierarchy
module Data.Foldable
module Data.Traversable
Mono hierarchy
module Data.MonoTraversable
module Data.Sequences
module Data.Sequences.Lazy
module Data.Textual.Encoding
module Data.Containers
I/O
data Handle
Haskell defines operations to read and write characters from and to files,
represented by values of type Handle
. Each value of this type is a
handle: a record used by the Haskell run-time system to manage I/O
with file system objects. A handle has at least the following properties:
- whether it manages input or output or both;
- whether it is open, closed or semi-closed;
- whether the object is seekable;
- whether buffering is disabled, or enabled on a line or block basis;
- a buffer (whose length may be zero).
Most handles will also have a current I/O position indicating where the next
input or output operation will occur. A handle is readable if it
manages only input or both input and output; likewise, it is writable if
it manages only output or both input and output. A handle is open when
first allocated.
Once it is closed it can no longer be used for either input or output,
though an implementation cannot re-use its storage while references
remain to it. Handles are in the Show
and Eq
classes. The string
produced by showing a handle is system dependent; it should include
enough information to identify the handle for debugging. A handle is
equal according to ==
only to itself; no attempt
is made to compare the internal state of different handles for equality.
Non-standard
List-like classes
concatMap :: (Monoid m, MonoFoldable c) => (Element c -> m) -> c -> mSource
length :: MonoFoldable c => c -> IntSource
null :: MonoFoldable c => c -> BoolSource
pack :: IsSequence c => [Element c] -> cSource
unpack :: MonoFoldable c => c -> [Element c]Source
repack :: (MonoFoldable a, IsSequence b, Element a ~ Element b) => a -> bSource
Repack from one type to another, dropping to a list in the middle.
repack = pack . unpack
.
toList :: MonoFoldable c => c -> [Element c]Source
mapM :: Traversable t => forall a m b. Monad m => (a -> m b) -> t a -> m (t b)
Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results.
mapM_ :: (Monad m, MonoFoldable c) => (Element c -> m a) -> c -> m ()Source
forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
forM_ :: (Monad m, MonoFoldable c) => c -> (Element c -> m a) -> m ()Source
foldl' :: MonoFoldable c => (a -> Element c -> a) -> a -> c -> aSource
foldr :: MonoFoldable c => (Element c -> b -> b) -> b -> c -> bSource
foldM :: (Monad m, MonoFoldable c) => (a -> Element c -> m a) -> a -> c -> m aSource
intercalate :: (Monoid (Element c), IsSequence c) => Element c -> c -> Element cSource
zipWith6 :: Zip6 f => (a -> b -> c -> d -> e -> g -> h) -> f a -> f b -> f c -> f d -> f e -> f g -> f hSource
zipWith7 :: Zip7 f => (a -> b -> c -> d -> e -> g -> h -> i) -> f a -> f b -> f c -> f d -> f e -> f g -> f h -> f iSource
hashNub :: (Hashable a, Eq a) => [a] -> [a]Source
same behavior as nub, but requires Hashable & Eq and is O(n log n) https:github.comnh2haskell-ordnub
ordNub :: Ord a => [a] -> [a]Source
same behavior as nub, but requires Ord and is O(n log n) https:github.comnh2haskell-ordnub
ordNubBy :: Ord b => (a -> b) -> (a -> a -> Bool) -> [a] -> [a]Source
same behavior as nubBy, but requires Ord and is O(n log n) https:github.comnh2haskell-ordnub
sortWith :: (Ord a, IsSequence c) => (Element c -> a) -> c -> cSource
Sort elements using the user supplied function to project something out of each element. Inspired by http://hackage.haskell.org/packages/archive/base/latest/doc/html/GHC-Exts.html#v:sortWith.
compareLength :: (Integral i, MonoFoldable c) => c -> i -> OrderingSource
Set-like
(\\) :: SetContainer a => a -> a -> aSource
An alias for difference
.
intersect :: SetContainer a => a -> a -> aSource
An alias for intersection
.
unions :: (MonoFoldable c, SetContainer (Element c)) => c -> Element cSource
Text-like
class Show a where
Conversion of values to readable String
s.
Minimal complete definition: showsPrec
or show
.
Derived instances of Show
have the following properties, which
are compatible with derived instances of Read
:
- The result of
show
is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used. - If the constructor is defined to be an infix operator, then
showsPrec
will produce infix applications of the constructor. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
x
is less thand
(associativity is ignored). Thus, ifd
is0
then the result is never surrounded in parentheses; ifd
is11
it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then
show
will produce the record-syntax form, with the fields given in the same order as the original declaration.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Show
is equivalent to
instance (Show a) => Show (Tree a) where showsPrec d (Leaf m) = showParen (d > app_prec) $ showString "Leaf " . showsPrec (app_prec+1) m where app_prec = 10 showsPrec d (u :^: v) = showParen (d > up_prec) $ showsPrec (up_prec+1) u . showString " :^: " . showsPrec (up_prec+1) v where up_prec = 5
Note that right-associativity of :^:
is ignored. For example,
-
produces the stringshow
(Leaf 1 :^: Leaf 2 :^: Leaf 3)"Leaf 1 :^: (Leaf 2 :^: Leaf 3)"
.
:: Int | the operator precedence of the enclosing
context (a number from |
-> a | the value to be converted to a |
-> ShowS |
Convert a value to a readable String
.
showsPrec
should satisfy the law
showsPrec d x r ++ s == showsPrec d x (r ++ s)
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.
Case conversion
charToLower :: Char -> CharSource
Convert a character to lower case.
Character-based case conversion is lossy in comparison to string-based toLower
.
For instance, 'İ' will be converted to 'i', instead of "i̇".
charToUpper :: Char -> CharSource
Convert a character to upper case.
Character-based case conversion is lossy in comparison to string-based toUpper
.
For instance, 'ß' won't be converted to "SS".
IO
class IsSequence a => IOData a whereSource
readFile :: MonadIO m => FilePath -> m aSource
writeFile :: MonadIO m => FilePath -> a -> m ()Source
getLine :: MonadIO m => m aSource
hGetContents :: MonadIO m => Handle -> m aSource
hGetLine :: MonadIO m => Handle -> m aSource
hPut :: MonadIO m => Handle -> a -> m ()Source
IOData LText | |
IOData LByteString | |
IOData Text | |
IOData ByteString | |
~ * Char c => IOData [c] |
Computation hClose
hdl
makes handle hdl
closed. Before the
computation finishes, if hdl
is writable its buffer is flushed as
for hFlush
.
Performing hClose
on a handle that has already been closed has no effect;
doing so is not an error. All other operations on a closed handle will fail.
If hClose
fails for any reason, any further operations (apart from
hClose
) on the handle will still fail as if hdl
had been successfully
closed.
FilePath
fpToString :: FilePath -> StringSource
fpFromString :: String -> FilePathSource
fpFromText :: Text -> FilePathSource
Exceptions
catchAny :: MonadBaseControl IO m => m a -> (SomeException -> m a) -> m aSource
A version of catch
which is specialized for any exception. This
simplifies usage as no explicit type signatures are necessary.
Note that since version 0.5.9, this function now has proper support for asynchronous exceptions, by only catching exceptions generated by the internal action.
Since 0.5.6
handleAny :: MonadBaseControl IO m => (SomeException -> m a) -> m a -> m aSource
A version of handle
which is specialized for any exception. This
simplifies usage as no explicit type signatures are necessary.
Note that since version 0.5.9, this function now has proper support for asynchronous exceptions, by only catching exceptions generated by the internal action.
Since 0.5.6
tryAny :: MonadBaseControl IO m => m a -> m (Either SomeException a)Source
A version of try
which is specialized for any exception.
This simplifies usage as no explicit type signatures are necessary.
Note that since version 0.5.9, this function now has proper support for asynchronous exceptions, by only catching exceptions generated by the internal action.
Since 0.5.6
catchAnyDeep :: (NFData a, MonadBaseControl IO m) => m a -> (SomeException -> m a) -> m aSource
An extension to catchAny
which ensures that the return value is fully
evaluated. See tryAnyDeep
.
Since 0.5.9
handleAnyDeep :: (NFData a, MonadBaseControl IO m) => (SomeException -> m a) -> m a -> m aSource
flip catchAnyDeep
Since 0.5.6
tryAnyDeep :: (NFData a, MonadBaseControl IO m) => m a -> m (Either SomeException a)Source
An extension to tryAny
which ensures that the return value is fully
evaluated. In other words, if you get a Right
response here, you can be
confident that using it will not result in another exception.
Since 0.5.9
catchIO :: MonadBaseControl IO m => m a -> (IOException -> m a) -> m aSource
A version of catch
which is specialized for IO exceptions. This
simplifies usage as no explicit type signatures are necessary.
Since 0.5.6
handleIO :: MonadBaseControl IO m => (IOException -> m a) -> m a -> m aSource
A version of handle
which is specialized for IO exceptions. This
simplifies usage as no explicit type signatures are necessary.
Since 0.5.6
tryIO :: MonadBaseControl IO m => m a -> m (Either IOException a)Source
A version of try
which is specialized for IO exceptions.
This simplifies usage as no explicit type signatures are necessary.
Since 0.5.6
Force types
Helper functions for situations where type inferer gets confused.
asIOException :: IOException -> IOExceptionSource
Since 0.5.6
asSomeException :: SomeException -> SomeExceptionSource
Since 0.5.6