| Copyright | (c) Daniel Mendler 2016 |
|---|---|
| License | MIT |
| Maintainer | mail@daniel-mendler.de |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
| Extensions |
|
Intro
Contents
Description
Intro is a modern Prelude which provides safe alternatives
for most of the partial functions and follows other
best practices, e.g., Text is preferred over String.
For String overloading the extension OverloadedStrings should be used.
Container types and Monad transformers are provided.
Most important - this Prelude tries to keep things simple. This means it just reexports from base and commonly used libraries and adds only very few additional functions.
List of design decisions:
- Keep everything at one place (There are one two modules and Intro.Trustworthy is only there for Safe Haskell)
- Conservative extension over the base Prelude
- Rely only on very common external libraries
- Avoid writing custom functions
- Export everything explicitly to provide a stable interface and for good documentation
- Export only total functions or provide safe alternatives (Very few exceptions like div etc.)
- Prefer Text over String, provide ConvertibleStrings
- Provide Monad transformers
- Provide container types
- Prefer generic functions
- Debugging functions, like
traceandundefinedare available but produce compile time warnings - Don't provide error, only panic instead
- Compatibility with Control.Lens
Some Prelude functions are missing from Intro. More general variants are available for the following functions:
>>=*>++=<>concat=mconcatfmapis replaced by generalizedmapmapM=traversemapM_=traverse_return=puresequence=sequenceAsequence_=sequenceA_
Unsafe functions are not provided. Use the '*May' or '*Def' alternatives instead.
cycle,head,tail,init,lastfoldl1,foldr1,maximum,minimumtoEnum,pred,succreadis replaced byreadMaybe
These functions are not provided for various reasons:
!!is unsafe and O(n). Use aMapinstead.lines,unlines,wordsandunwordsare not provided. Use qualifiedTextimport instead.- Instead of
foldl, it is recommended to usefoldl'. lexis not commonly used. Use a parser combinator library instead.gcdandlcmare not commonly used.erroranderrorWithoutStackTraceare not provided. Usepanicinstead.ioErroranduserErrorare not provided. Import modules for exception handling separately if needed.- Some
ReadandShowclass functions are not provided. Don't write these instances yourself.
Additional types and functions:
LTextalias for lazyTextLByteStringalias for lazyByteStringfromFoldableto convert fromFoldableto anIsListtypeconvertListto convert between twoIsListtypes. This function can be used instead of thetoListfunction originally provided by theIsListclass.showTandshowSare monomorphicshowfunctions.<>^lifted composition.:function composition?:as an alias forfromMaybeskipas an alias forpure ()panicas a replacement forerror
- const :: a -> b -> a
- flip :: (a -> b -> c) -> b -> a -> c
- ($) :: (a -> b) -> a -> b
- ($!) :: (a -> b) -> a -> b
- (&) :: a -> (a -> b) -> b
- fix :: (a -> a) -> a
- on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
- (.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
- until :: (a -> Bool) -> (a -> a) -> a -> a
- asTypeOf :: a -> a -> a
- seq :: a -> b -> b
- data Void :: *
- data Bool :: *
- (&&) :: Bool -> Bool -> Bool
- (||) :: Bool -> Bool -> Bool
- bool :: a -> a -> Bool -> a
- not :: Bool -> Bool
- otherwise :: Bool
- data Maybe a :: * -> *
- catMaybes :: [Maybe a] -> [a]
- fromMaybe :: a -> Maybe a -> a
- (?:) :: Maybe a -> a -> a
- isJust :: Maybe a -> Bool
- isNothing :: Maybe a -> Bool
- mapMaybe :: (a -> Maybe b) -> [a] -> [b]
- maybe :: b -> (a -> b) -> Maybe a -> b
- class IsList l where
- convertList :: (IsList a, IsList b, Item a ~ Item b) => a -> b
- fromFoldable :: (Foldable f, IsList a) => f (Item a) -> a
- break :: (a -> Bool) -> [a] -> ([a], [a])
- breakOn :: Eq a => [a] -> [a] -> ([a], [a])
- breakOnEnd :: Eq a => [a] -> [a] -> ([a], [a])
- drop :: Int -> [a] -> [a]
- dropEnd :: Int -> [a] -> [a]
- dropWhile :: (a -> Bool) -> [a] -> [a]
- dropWhileEnd :: (a -> Bool) -> [a] -> [a]
- filter :: (a -> Bool) -> [a] -> [a]
- group :: Eq a => [a] -> [[a]]
- groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
- groupOn :: Eq b => (a -> b) -> [a] -> [[a]]
- groupSort :: Ord k => [(k, v)] -> [(k, [v])]
- groupSortBy :: (a -> a -> Ordering) -> [a] -> [[a]]
- groupSortOn :: Ord b => (a -> b) -> [a] -> [[a]]
- inits :: [a] -> [[a]]
- intercalate :: [a] -> [[a]] -> [a]
- intersperse :: a -> [a] -> [a]
- isPrefixOf :: Eq a => [a] -> [a] -> Bool
- isSuffixOf :: Eq a => [a] -> [a] -> Bool
- iterate :: (a -> a) -> a -> [a]
- lookup :: Eq a => a -> [(a, b)] -> Maybe b
- nubOrd :: Ord a => [a] -> [a]
- nubOrdBy :: (a -> a -> Ordering) -> [a] -> [a]
- nubOrdOn :: Ord b => (a -> b) -> [a] -> [a]
- permutations :: [a] -> [[a]]
- repeat :: a -> [a]
- replicate :: Int -> a -> [a]
- reverse :: [a] -> [a]
- scanl :: (b -> a -> b) -> b -> [a] -> [b]
- scanr :: (a -> b -> b) -> b -> [a] -> [b]
- sort :: Ord a => [a] -> [a]
- sortBy :: (a -> a -> Ordering) -> [a] -> [a]
- sortOn :: Ord b => (a -> b) -> [a] -> [a]
- span :: (a -> Bool) -> [a] -> ([a], [a])
- spanEnd :: (a -> Bool) -> [a] -> ([a], [a])
- splitAt :: Int -> [a] -> ([a], [a])
- split :: (a -> Bool) -> [a] -> [[a]]
- splitOn :: Eq a => [a] -> [a] -> [[a]]
- subsequences :: [a] -> [[a]]
- tails :: [a] -> [[a]]
- take :: Int -> [a] -> [a]
- takeEnd :: Int -> [a] -> [a]
- takeWhile :: (a -> Bool) -> [a] -> [a]
- transpose :: [[a]] -> [[a]]
- unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
- unzip :: [(a, b)] -> ([a], [b])
- unzip3 :: [(a, b, c)] -> ([a], [b], [c])
- zip :: [a] -> [b] -> [(a, b)]
- zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
- zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
- headDef :: a -> [a] -> a
- headMay :: [a] -> Maybe a
- initDef :: [a] -> [a] -> [a]
- initMay :: [a] -> Maybe [a]
- lastDef :: a -> [a] -> a
- lastMay :: [a] -> Maybe a
- tailDef :: [a] -> [a] -> [a]
- tailMay :: [a] -> Maybe [a]
- cycleMay :: [a] -> Maybe [a]
- cycleDef :: [a] -> [a] -> [a]
- data NonEmpty a :: * -> * = a :| [a]
- scanl1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a
- scanr1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a
- fst :: (a, b) -> a
- snd :: (a, b) -> b
- curry :: ((a, b) -> c) -> a -> b -> c
- uncurry :: (a -> b -> c) -> (a, b) -> c
- swap :: (a, b) -> (b, a)
- data Either a b :: * -> * -> *
- either :: (a -> c) -> (b -> c) -> Either a b -> c
- fromLeft :: a -> Either a b -> a
- fromRight :: b -> Either a b -> b
- isLeft :: Either a b -> Bool
- isRight :: Either a b -> Bool
- lefts :: [Either a b] -> [a]
- rights :: [Either a b] -> [b]
- partitionEithers :: [Either a b] -> ([a], [b])
- eitherToMaybe :: Either a b -> Maybe b
- maybeToEither :: a -> Maybe b -> Either a b
- data Char :: *
- type String = [Char]
- data Text :: *
- type LText = Text
- data ByteString :: *
- type LByteString = ByteString
- class IsString a where
- class ConvertibleStrings a b where
- data Map k a :: * -> * -> *
- data Set a :: * -> *
- data IntMap a :: * -> *
- data IntSet :: *
- data HashMap k v :: * -> * -> *
- data HashSet a :: * -> *
- class Hashable a where
- class Hashable1 t
- class Hashable2 t
- data Seq a :: * -> *
- data DList a :: * -> *
- data Integer :: *
- data Natural :: *
- data Int :: *
- data Int8 :: *
- data Int16 :: *
- data Int32 :: *
- data Int64 :: *
- data Word :: *
- data Word8 :: *
- data Word16 :: *
- data Word32 :: *
- data Word64 :: *
- data Float :: *
- data Double :: *
- data Ratio a :: * -> *
- type Rational = Ratio Integer
- (%) :: Integral a => a -> a -> Ratio a
- numerator :: Ratio a -> a
- denominator :: Ratio a -> a
- approxRational :: RealFrac a => a -> a -> Rational
- class Num a where
- subtract :: Num a => a -> a -> a
- (^) :: (Num a, Integral b) => a -> b -> a
- class (Num a, Ord a) => Real a where
- realToFrac :: (Real a, Fractional b) => a -> b
- class (Real a, Enum a) => Integral a where
- fromIntegral :: (Integral a, Num b) => a -> b
- even :: Integral a => a -> Bool
- odd :: Integral a => a -> Bool
- class Num a => Fractional a where
- (^^) :: (Fractional a, Integral b) => a -> b -> a
- class Fractional a => Floating a where
- class (Real a, Fractional a) => RealFrac a where
- class (RealFrac a, Floating a) => RealFloat a where
- class Eq a => Bits a where
- class Bits b => FiniteBits b where
- class Show a
- class Show1 f
- class Show2 f
- show :: (Show a, ConvertibleStrings String b) => a -> b
- showT :: Show a => a -> Text
- showS :: Show a => a -> String
- class Read a
- class Read1 f
- class Read2 f
- readMaybe :: (Read b, ConvertibleStrings a String) => a -> Maybe b
- class Eq a where
- class Eq1 f
- class Eq2 f
- class Eq a => Ord a where
- class Eq1 f => Ord1 f
- class Eq2 f => Ord2 f
- data Ordering :: *
- newtype Down a :: * -> * = Down a
- comparing :: Ord a => (b -> a) -> b -> b -> Ordering
- class Enum a where
- toEnumMay :: (Enum a, Bounded a) => Int -> Maybe a
- toEnumDef :: (Enum a, Bounded a) => a -> Int -> a
- predMay :: (Enum a, Eq a, Bounded a) => a -> Maybe a
- predDef :: (Enum a, Eq a, Bounded a) => a -> a -> a
- succMay :: (Enum a, Eq a, Bounded a) => a -> Maybe a
- succDef :: (Enum a, Eq a, Bounded a) => a -> a -> a
- class Bounded a where
- class Category k cat where
- (<<<) :: Category k cat => cat b c -> cat a b -> cat a c
- (>>>) :: Category k cat => cat a b -> cat b c -> cat a c
- class Semigroup a where
- newtype First a :: * -> * = First {
- getFirst :: a
- newtype Last a :: * -> * = Last {
- getLast :: a
- newtype Min a :: * -> * = Min {
- getMin :: a
- newtype Max a :: * -> * = Max {
- getMax :: a
- newtype Option a :: * -> * = Option {}
- class Monoid a where
- newtype Dual a :: * -> * = Dual {
- getDual :: a
- newtype Endo a :: * -> * = Endo {
- appEndo :: a -> a
- newtype All :: * = All {}
- newtype Any :: * = Any {}
- newtype Alt k f a :: forall k. (k -> *) -> k -> * = Alt {
- getAlt :: f a
- class Functor f where
- ($>) :: Functor f => f a -> b -> f b
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- map :: Functor f => (a -> b) -> f a -> f b
- void :: Functor f => f a -> f ()
- newtype Const k a b :: forall k. * -> k -> * = Const {
- getConst :: a
- newtype Identity a :: * -> * = Identity {
- runIdentity :: a
- class Foldable t where
- null :: Foldable t => forall a. t a -> Bool
- length :: Foldable t => forall a. t a -> Int
- foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b
- foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
- for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
- asum :: (Foldable t, Alternative f) => t (f a) -> f a
- concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
- all :: Foldable t => (a -> Bool) -> t a -> Bool
- any :: Foldable t => (a -> Bool) -> t a -> Bool
- or :: Foldable t => t Bool -> Bool
- and :: Foldable t => t Bool -> Bool
- find :: Foldable t => (a -> Bool) -> t a -> Maybe a
- notElem :: (Foldable t, Eq a) => a -> t a -> Bool
- sequenceA_ :: (Foldable t, Applicative f) => t (f a) -> f ()
- foldl1May :: Foldable t => (a -> a -> a) -> t a -> Maybe a
- foldl1Def :: Foldable t => a -> (a -> a -> a) -> t a -> a
- foldr1May :: Foldable t => (a -> a -> a) -> t a -> Maybe a
- foldr1Def :: Foldable t => a -> (a -> a -> a) -> t a -> a
- maximumByMay :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a
- maximumByDef :: Foldable t => a -> (a -> a -> Ordering) -> t a -> a
- minimumByMay :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a
- minimumByDef :: Foldable t => a -> (a -> a -> Ordering) -> t a -> a
- maximumMay :: (Foldable t, Ord a) => t a -> Maybe a
- maximumDef :: (Foldable t, Ord a) => a -> t a -> a
- minimumMay :: (Foldable t, Ord a) => t a -> Maybe a
- minimumDef :: (Foldable t, Ord a) => a -> t a -> a
- class (Functor t, Foldable t) => Traversable t where
- for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b)
- mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)
- mapAccumR :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)
- class Functor f => Applicative f where
- newtype ZipList a :: * -> * = ZipList {
- getZipList :: [a]
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- skip :: Applicative m => m ()
- (<>^) :: (Applicative f, Semigroup a) => f a -> f a -> f a
- class Applicative f => Alternative f where
- optional :: Alternative f => f a -> f (Maybe a)
- some1 :: Alternative f => f a -> f (NonEmpty a)
- class Applicative m => Monad m where
- class Monad m => MonadFail m where
- class Monad m => MonadFix m where
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- class (Alternative m, Monad m) => MonadPlus m where
- join :: Monad m => m (m a) -> m a
- guard :: Alternative f => Bool -> f ()
- when :: Applicative f => Bool -> f () -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- replicateM :: Applicative m => Int -> m a -> m [a]
- replicateM_ :: Applicative m => Int -> m a -> m ()
- (<$!>) :: Monad m => (a -> b) -> m a -> m b
- whenM :: Monad m => m Bool -> m () -> m ()
- unlessM :: Monad m => m Bool -> m () -> m ()
- ifM :: Monad m => m Bool -> m a -> m a -> m a
- allM :: Monad m => (a -> m Bool) -> [a] -> m Bool
- anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool
- andM :: Monad m => [m Bool] -> m Bool
- orM :: Monad m => [m Bool] -> m Bool
- concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
- (&&^) :: Monad m => m Bool -> m Bool -> m Bool
- (||^) :: Monad m => m Bool -> m Bool -> m Bool
- class Bifunctor p where
- class Bifoldable p where
- bifoldl' :: Bifoldable t => (a -> b -> a) -> (a -> c -> a) -> a -> t b c -> a
- bifoldr' :: Bifoldable t => (a -> c -> c) -> (b -> c -> c) -> c -> t a b -> c
- bitraverse_ :: (Bifoldable t, Applicative f) => (a -> f c) -> (b -> f d) -> t a b -> f ()
- bisequenceA_ :: (Bifoldable t, Applicative f) => t (f a) (f b) -> f ()
- bifor_ :: (Bifoldable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f ()
- class (Bifunctor t, Bifoldable t) => Bitraversable t where
- bifor :: (Bitraversable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f (t c d)
- bisequenceA :: (Bitraversable t, Applicative f) => t (f a) (f b) -> f (t a b)
- class MonadTrans t where
- newtype MaybeT m a :: (* -> *) -> * -> * = MaybeT {}
- mapMaybeT :: (m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b
- class Monad m => MonadError e m | m -> e where
- type Except e = ExceptT e Identity
- runExcept :: Except e a -> Either e a
- mapExcept :: (Either e a -> Either e' b) -> Except e a -> Except e' b
- withExcept :: (e -> e') -> Except e a -> Except e' a
- newtype ExceptT e m a :: * -> (* -> *) -> * -> * = ExceptT (m (Either e a))
- runExceptT :: ExceptT e m a -> m (Either e a)
- mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b
- withExceptT :: Functor m => (e -> e') -> ExceptT e m a -> ExceptT e' m a
- class Monad m => MonadReader r m | m -> r where
- asks :: MonadReader r m => (r -> a) -> m a
- type Reader r = ReaderT * r Identity
- runReader :: Reader r a -> r -> a
- mapReader :: (a -> b) -> Reader r a -> Reader r b
- withReader :: (r' -> r) -> Reader r a -> Reader r' a
- newtype ReaderT k r m a :: forall k. * -> (k -> *) -> k -> * = ReaderT {
- runReaderT :: r -> m a
- mapReaderT :: (m a -> n b) -> ReaderT k1 r m a -> ReaderT k r n b
- withReaderT :: (r' -> r) -> ReaderT k r m a -> ReaderT k r' m a
- class (Monoid w, Monad m) => MonadWriter w m | m -> w where
- type Writer w = WriterT w Identity
- runWriter :: Monoid w => Writer w a -> (a, w)
- execWriter :: Monoid w => Writer w a -> w
- mapWriter :: (Monoid w, Monoid w') => ((a, w) -> (b, w')) -> Writer w a -> Writer w' b
- data WriterT w m a :: * -> (* -> *) -> * -> *
- writerT :: (Functor m, Monoid w) => m (a, w) -> WriterT w m a
- runWriterT :: Monoid w => WriterT w m a -> m (a, w)
- execWriterT :: (Monad m, Monoid w) => WriterT w m a -> m w
- mapWriterT :: (Monad n, Monoid w, Monoid w') => (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
- class Monad m => MonadState s m | m -> s where
- type State s = StateT s Identity
- gets :: MonadState s m => (s -> a) -> m a
- modify :: MonadState s m => (s -> s) -> m ()
- modify' :: MonadState s m => (s -> s) -> m ()
- runState :: State s a -> s -> (a, s)
- evalState :: State s a -> s -> a
- execState :: State s a -> s -> s
- mapState :: ((a, s) -> (b, s)) -> State s a -> State s b
- withState :: (s -> s) -> State s a -> State s a
- newtype StateT s m a :: * -> (* -> *) -> * -> * = StateT {
- runStateT :: s -> m (a, s)
- evalStateT :: Monad m => StateT s m a -> s -> m a
- execStateT :: Monad m => StateT s m a -> s -> m s
- mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
- withStateT :: (s -> s) -> StateT s m a -> StateT s m a
- class (Monoid w, MonadReader r m, MonadWriter w m, MonadState s m) => MonadRWS r w s m | m -> r, m -> w, m -> s
- type RWS r w s = RWST r w s Identity
- rws :: Monoid w => (r -> s -> (a, s, w)) -> RWS r w s a
- runRWS :: Monoid w => RWS r w s a -> r -> s -> (a, s, w)
- evalRWS :: Monoid w => RWS r w s a -> r -> s -> (a, w)
- execRWS :: Monoid w => RWS r w s a -> r -> s -> (s, w)
- mapRWS :: (Monoid w, Monoid w') => ((a, s, w) -> (b, s, w')) -> RWS r w s a -> RWS r w' s b
- data RWST r w s m a :: * -> * -> * -> (* -> *) -> * -> *
- rwsT :: (Functor m, Monoid w) => (r -> s -> m (a, s, w)) -> RWST r w s m a
- runRWST :: Monoid w => RWST r w s m a -> r -> s -> m (a, s, w)
- evalRWST :: (Monad m, Monoid w) => RWST r w s m a -> r -> s -> m (a, w)
- execRWST :: (Monad m, Monoid w) => RWST r w s m a -> r -> s -> m (s, w)
- mapRWST :: (Monad n, Monoid w, Monoid w') => (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
- class Generic a
- class Generic1 f
- class Typeable k a
- class NFData a
- class Binary t
- type Type = *
- data Constraint :: *
- data Proxy k t :: forall k. k -> * = Proxy
- newtype Tagged k s b :: forall k. k -> * -> * = Tagged {
- unTagged :: b
- unTagged :: Tagged k s b -> b
- data IO a :: * -> *
- class Monad m => MonadIO m where
- getChar :: MonadIO m => m Char
- getContents :: MonadIO m => m Text
- getLine :: MonadIO m => m Text
- print :: (MonadIO m, Show a) => a -> m ()
- putChar :: MonadIO m => Char -> m ()
- putStr :: MonadIO m => Text -> m ()
- putStrLn :: MonadIO m => Text -> m ()
- type FilePath = String
- readFile :: MonadIO m => FilePath -> m ByteString
- writeFile :: MonadIO m => FilePath -> ByteString -> m ()
- appendFile :: MonadIO m => FilePath -> ByteString -> m ()
- readFileUtf8 :: MonadIO m => FilePath -> m Text
- writeFileUtf8 :: MonadIO m => FilePath -> Text -> m ()
- appendFileUtf8 :: MonadIO m => FilePath -> Text -> m ()
- panic :: HasCallStack => Text -> a
- undefined :: HasCallStack => a
- trace :: Text -> a -> a
- traceIO :: MonadIO m => Text -> m ()
- traceM :: Applicative m => Text -> m ()
- traceShow :: Show a => a -> b -> b
- traceShowM :: (Show a, Applicative m) => a -> m ()
Basic functions
const x is a unary function which evaluates to x for all inputs.
For instance,
>>>map (const 42) [0..3][42,42,42,42]
flip :: (a -> b -> c) -> b -> a -> c #
takes its (first) two arguments in the reverse order of flip ff.
($) :: (a -> b) -> a -> b infixr 0 #
Application operator. This operator is redundant, since ordinary
application (f x) means the same as (f . However, $ x)$ has
low, right-associative binding precedence, so it sometimes allows
parentheses to be omitted; for example:
f $ g $ h x = f (g (h x))
It is also useful in higher-order situations, such as ,
or map ($ 0) xs.zipWith ($) fs xs
($!) :: (a -> b) -> a -> b infixr 0 #
Strict (call-by-value) application operator. It takes a function and an argument, evaluates the argument to weak head normal form (WHNF), then calls the function with that value.
is the least fixed point of the function fix ff,
i.e. the least defined x such that f x = x.
(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d infixr 8 Source #
Compose functions with one argument with function with two arguments.
f .: g = \x y -> f (g x y).
until :: (a -> Bool) -> (a -> a) -> a -> a #
yields the result of applying until p ff until p holds.
The value of seq a b is bottom if a is bottom, and
otherwise equal to b. seq is usually introduced to
improve performance by avoiding unneeded laziness.
A note on evaluation order: the expression seq a b does
not guarantee that a will be evaluated before b.
The only guarantee given by seq is that the both a
and b will be evaluated before seq returns a value.
In particular, this means that b may be evaluated before
a. If you need to guarantee a specific order of evaluation,
you must use the function pseq from the "parallel" package.
Basic algebraic types
Void
Uninhabited data type
Since: 4.8.0.0
Bool
Case analysis for the Bool type. evaluates to bool x y px
when p is False, and evaluates to y when p is True.
This is equivalent to if p then y else x; that is, one can
think of it as an if-then-else construct with its arguments
reordered.
Examples
Basic usage:
>>>bool "foo" "bar" True"bar">>>bool "foo" "bar" False"foo"
Confirm that and bool x y pif p then y else x are
equivalent:
>>>let p = True; x = "bar"; y = "foo">>>bool x y p == if p then y else xTrue>>>let p = False>>>bool x y p == if p then y else xTrue
Since: 4.7.0.0
Maybe
The Maybe type encapsulates an optional value. A value of type
either contains a value of type Maybe aa (represented as ),
or it is empty (represented as Just aNothing). Using Maybe is a good way to
deal with errors or exceptional cases without resorting to drastic
measures such as error.
The Maybe type is also a monad. It is a simple kind of error
monad, where all errors are represented by Nothing. A richer
error monad can be built using the Either type.
Instances
| Monad Maybe | |
| Functor Maybe | |
| MonadFix Maybe | |
| MonadFail Maybe | |
| Applicative Maybe | |
| Foldable Maybe | |
| Traversable Maybe | |
| Generic1 Maybe | |
| Eq1 Maybe | |
| Ord1 Maybe | |
| Read1 Maybe | |
| Show1 Maybe | |
| Alternative Maybe | |
| MonadPlus Maybe | |
| Hashable1 Maybe | |
| Eq a => Eq (Maybe a) | |
| Ord a => Ord (Maybe a) | |
| Read a => Read (Maybe a) | |
| Show a => Show (Maybe a) | |
| Generic (Maybe a) | |
| Semigroup a => Semigroup (Maybe a) | |
| Monoid a => Monoid (Maybe a) | Lift a semigroup into |
| Binary a => Binary (Maybe a) | |
| NFData a => NFData (Maybe a) | |
| Hashable a => Hashable (Maybe a) | |
| SingI (Maybe a) (Nothing a) | |
| SingKind a (KProxy a) => SingKind (Maybe a) (KProxy (Maybe a)) | |
| SingI a a1 => SingI (Maybe a) (Just a a1) | |
| type Rep1 Maybe | |
| type Rep (Maybe a) | |
| data Sing (Maybe a) | |
| type (==) (Maybe k) a b | |
| type DemoteRep (Maybe a) (KProxy (Maybe a)) | |
catMaybes :: [Maybe a] -> [a] #
The catMaybes function takes a list of Maybes and returns
a list of all the Just values.
Examples
Basic usage:
>>>catMaybes [Just 1, Nothing, Just 3][1,3]
When constructing a list of Maybe values, catMaybes can be used
to return all of the "success" results (if the list is the result
of a map, then mapMaybe would be more appropriate):
>>>import Text.Read ( readMaybe )>>>[readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ][Just 1,Nothing,Just 3]>>>catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ][1,3]
fromMaybe :: a -> Maybe a -> a #
The fromMaybe function takes a default value and and Maybe
value. If the Maybe is Nothing, it returns the default values;
otherwise, it returns the value contained in the Maybe.
Examples
Basic usage:
>>>fromMaybe "" (Just "Hello, World!")"Hello, World!"
>>>fromMaybe "" Nothing""
Read an integer from a string using readMaybe. If we fail to
parse an integer, we want to return 0 by default:
>>>import Text.Read ( readMaybe )>>>fromMaybe 0 (readMaybe "5")5>>>fromMaybe 0 (readMaybe "")0
mapMaybe :: (a -> Maybe b) -> [a] -> [b] #
The mapMaybe function is a version of map which can throw
out elements. In particular, the functional argument returns
something of type . If this is Maybe bNothing, no element
is added on to the result list. If it is , then Just bb is
included in the result list.
Examples
Using is a shortcut for mapMaybe f x
in most cases:catMaybes $ map f x
>>>import Text.Read ( readMaybe )>>>let readMaybeInt = readMaybe :: String -> Maybe Int>>>mapMaybe readMaybeInt ["1", "Foo", "3"][1,3]>>>catMaybes $ map readMaybeInt ["1", "Foo", "3"][1,3]
If we map the Just constructor, the entire list should be returned:
>>>mapMaybe Just [1,2,3][1,2,3]
maybe :: b -> (a -> b) -> Maybe a -> b #
The maybe function takes a default value, a function, and a Maybe
value. If the Maybe value is Nothing, the function returns the
default value. Otherwise, it applies the function to the value inside
the Just and returns the result.
Examples
Basic usage:
>>>maybe False odd (Just 3)True
>>>maybe False odd NothingFalse
Read an integer from a string using readMaybe. If we succeed,
return twice the integer; that is, apply (*2) to it. If instead
we fail to parse an integer, return 0 by default:
>>>import Text.Read ( readMaybe )>>>maybe 0 (*2) (readMaybe "5")10>>>maybe 0 (*2) (readMaybe "")0
Apply show to a Maybe Int. If we have Just n, we want to show
the underlying Int n. But if we have Nothing, we return the
empty string instead of (for example) "Nothing":
>>>maybe "" show (Just 5)"5">>>maybe "" show Nothing""
List
The IsList class and its methods are intended to be used in
conjunction with the OverloadedLists extension.
Since: 4.7.0.0
Associated Types
The Item type function returns the type of items of the structure
l.
Methods
The fromList function constructs the structure l from the given
list of Item l
Instances
| IsList CallStack | Be aware that 'fromList . toList = id' only for unfrozen Since: 4.9.0.0 |
| IsList Version | Since: 4.8.0.0 |
| IsList IntSet | |
| IsList [a] | |
| IsList (NonEmpty a) | |
| IsList (IntMap a) | |
| IsList (Seq a) | |
| Ord a => IsList (Set a) | |
| IsList (DList a) | |
| (Eq a, Hashable a) => IsList (HashSet a) | |
| Ord k => IsList (Map k v) | |
| (Eq k, Hashable k) => IsList (HashMap k v) | |
break :: (a -> Bool) -> [a] -> ([a], [a]) #
break, applied to a predicate p and a list xs, returns a tuple where
first element is longest prefix (possibly empty) of xs of elements that
do not satisfy p and second element is the remainder of the list:
break (> 3) [1,2,3,4,1,2,3,4] == ([1,2,3],[4,1,2,3,4]) break (< 9) [1,2,3] == ([],[1,2,3]) break (> 9) [1,2,3] == ([1,2,3],[])
breakOn :: Eq a => [a] -> [a] -> ([a], [a]) #
Find the first instance of needle in haystack.
The first element of the returned tuple
is the prefix of haystack before needle is matched. The second
is the remainder of haystack, starting with the match.
If you want the remainder without the patch, use stripInfix.
breakOn "::" "a::b::c" == ("a", "::b::c")
breakOn "/" "foobar" == ("foobar", "")
\needle haystack -> let (prefix,match) = breakOn needle haystack in prefix ++ match == haystackbreakOnEnd :: Eq a => [a] -> [a] -> ([a], [a]) #
Similar to breakOn, but searches from the end of the
string.
The first element of the returned tuple is the prefix of haystack
up to and including the last match of needle. The second is the
remainder of haystack, following the match.
breakOnEnd "::" "a::b::c" == ("a::b::", "c")drop n xs returns the suffix of xs
after the first n elements, or [] if n > :length xs
drop 6 "Hello World!" == "World!" drop 3 [1,2,3,4,5] == [4,5] drop 3 [1,2] == [] drop 3 [] == [] drop (-1) [1,2] == [1,2] drop 0 [1,2] == [1,2]
It is an instance of the more general genericDrop,
in which n may be of any integral type.
dropEnd :: Int -> [a] -> [a] #
Drop a number of elements from the end of the list.
dropEnd 3 "hello" == "he" dropEnd 5 "bye" == "" dropEnd (-1) "bye" == "bye" \i xs -> dropEnd i xs `isPrefixOf` xs \i xs -> length (dropEnd i xs) == max 0 (length xs - max 0 i) \i -> take 3 (dropEnd 5 [i..]) == take 3 [i..]
dropWhileEnd :: (a -> Bool) -> [a] -> [a] #
The dropWhileEnd function drops the largest suffix of a list
in which the given predicate holds for all elements. For example:
dropWhileEnd isSpace "foo\n" == "foo"
dropWhileEnd isSpace "foo bar" == "foo bar"
dropWhileEnd isSpace ("foo\n" ++ undefined) == "foo" ++ undefinedSince: 4.5.0.0
filter :: (a -> Bool) -> [a] -> [a] #
filter, applied to a predicate and a list, returns the list of
those elements that satisfy the predicate; i.e.,
filter p xs = [ x | x <- xs, p x]
group :: Eq a => [a] -> [[a]] #
The group function takes a list and returns a list of lists such
that the concatenation of the result is equal to the argument. Moreover,
each sublist in the result contains only equal elements. For example,
group "Mississippi" = ["M","i","ss","i","ss","i","pp","i"]
It is a special case of groupBy, which allows the programmer to supply
their own equality test.
groupOn :: Eq b => (a -> b) -> [a] -> [[a]] #
A version of group where the equality is done on some extracted value.
groupSortBy :: (a -> a -> Ordering) -> [a] -> [[a]] #
groupSortOn :: Ord b => (a -> b) -> [a] -> [[a]] #
intercalate :: [a] -> [[a]] -> [a] #
intercalate xs xss is equivalent to (.
It inserts the list concat (intersperse xs xss))xs in between the lists in xss and concatenates the
result.
intersperse :: a -> [a] -> [a] #
The intersperse function takes an element and a list and
`intersperses' that element between the elements of the list.
For example,
intersperse ',' "abcde" == "a,b,c,d,e"
isPrefixOf :: Eq a => [a] -> [a] -> Bool #
The isPrefixOf function takes two lists and returns True
iff the first list is a prefix of the second.
isSuffixOf :: Eq a => [a] -> [a] -> Bool #
The isSuffixOf function takes two lists and returns True iff
the first list is a suffix of the second. The second list must be
finite.
iterate :: (a -> a) -> a -> [a] #
iterate f x returns an infinite list of repeated applications
of f to x:
iterate f x == [x, f x, f (f x), ...]
lookup :: Eq a => a -> [(a, b)] -> Maybe b #
lookup key assocs looks up a key in an association list.
nubOrd :: Ord a => [a] -> [a] #
O(n log n). The nubOrd function removes duplicate elements from a list.
In particular, it keeps only the first occurrence of each element.
Unlike the standard nub operator, this version requires an Ord instance
and consequently runs asymptotically faster.
nubOrd "this is a test" == "this ae"
nubOrd (take 4 ("this" ++ undefined)) == "this"
\xs -> nubOrd xs == nub xsnubOrdBy :: (a -> a -> Ordering) -> [a] -> [a] #
A version of nubOrd with a custom predicate.
nubOrdBy (compare `on` length) ["a","test","of","this"] == ["a","test","of"]
nubOrdOn :: Ord b => (a -> b) -> [a] -> [a] #
A version of nubOrd which operates on a portion of the value.
nubOrdOn length ["a","test","of","this"] == ["a","test","of"]
permutations :: [a] -> [[a]] #
The permutations function returns the list of all permutations of the argument.
permutations "abc" == ["abc","bac","cba","bca","cab","acb"]
replicate :: Int -> a -> [a] #
replicate n x is a list of length n with x the value of
every element.
It is an instance of the more general genericReplicate,
in which n may be of any integral type.
sortOn :: Ord b => (a -> b) -> [a] -> [a] #
Sort a list by comparing the results of a key function applied to each
element. sortOn f is equivalent to sortBy (comparing f), but has the
performance advantage of only evaluating f once for each element in the
input list. This is called the decorate-sort-undecorate paradigm, or
Schwartzian transform.
Since: 4.8.0.0
span :: (a -> Bool) -> [a] -> ([a], [a]) #
span, applied to a predicate p and a list xs, returns a tuple where
first element is longest prefix (possibly empty) of xs of elements that
satisfy p and second element is the remainder of the list:
span (< 3) [1,2,3,4,1,2,3,4] == ([1,2],[3,4,1,2,3,4]) span (< 9) [1,2,3] == ([1,2,3],[]) span (< 0) [1,2,3] == ([],[1,2,3])
spanEnd :: (a -> Bool) -> [a] -> ([a], [a]) #
Span, but from the end.
spanEnd isUpper "youRE" == ("you","RE")
spanEnd (not . isSpace) "x y z" == ("x y ","z")
\f xs -> uncurry (++) (spanEnd f xs) == xs
\f xs -> spanEnd f xs == swap (both reverse (span f (reverse xs)))splitAt :: Int -> [a] -> ([a], [a]) #
splitAt n xs returns a tuple where first element is xs prefix of
length n and second element is the remainder of the list:
splitAt 6 "Hello World!" == ("Hello ","World!")
splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5])
splitAt 1 [1,2,3] == ([1],[2,3])
splitAt 3 [1,2,3] == ([1,2,3],[])
splitAt 4 [1,2,3] == ([1,2,3],[])
splitAt 0 [1,2,3] == ([],[1,2,3])
splitAt (-1) [1,2,3] == ([],[1,2,3])It is equivalent to ( when take n xs, drop n xs)n is not _|_
(splitAt _|_ xs = _|_).
splitAt is an instance of the more general genericSplitAt,
in which n may be of any integral type.
split :: (a -> Bool) -> [a] -> [[a]] #
Splits a list into components delimited by separators, where the predicate returns True for a separator element. The resulting components do not contain the separators. Two adjacent separators result in an empty component in the output.
split (== 'a') "aabbaca" == ["","","bb","c",""] split (== 'a') "" == [""] split (== ':') "::xyz:abc::123::" == ["","","xyz","abc","","123","",""] split (== ',') "my,list,here" == ["my","list","here"]
splitOn :: Eq a => [a] -> [a] -> [[a]] #
Break a list into pieces separated by the first list argument, consuming the delimiter. An empty delimiter is invalid, and will cause an error to be raised.
splitOn "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"] splitOn "aaa" "aaaXaaaXaaaXaaa" == ["","X","X","X",""] splitOn "x" "x" == ["",""] splitOn "x" "" == [""] \s x -> s /= "" ==> intercalate s (splitOn s x) == x \c x -> splitOn [c] x == split (==c) x
subsequences :: [a] -> [[a]] #
The subsequences function returns the list of all subsequences of the argument.
subsequences "abc" == ["","a","b","ab","c","ac","bc","abc"]
take n, applied to a list xs, returns the prefix of xs
of length n, or xs itself if n > :length xs
take 5 "Hello World!" == "Hello" take 3 [1,2,3,4,5] == [1,2,3] take 3 [1,2] == [1,2] take 3 [] == [] take (-1) [1,2] == [] take 0 [1,2] == []
It is an instance of the more general genericTake,
in which n may be of any integral type.
takeEnd :: Int -> [a] -> [a] #
Take a number of elements from the end of the list.
takeEnd 3 "hello" == "llo" takeEnd 5 "bye" == "bye" takeEnd (-1) "bye" == "" \i xs -> takeEnd i xs `isSuffixOf` xs \i xs -> length (takeEnd i xs) == min (max 0 i) (length xs)
takeWhile :: (a -> Bool) -> [a] -> [a] #
takeWhile, applied to a predicate p and a list xs, returns the
longest prefix (possibly empty) of xs of elements that satisfy p:
takeWhile (< 3) [1,2,3,4,1,2,3,4] == [1,2] takeWhile (< 9) [1,2,3] == [1,2,3] takeWhile (< 0) [1,2,3] == []
The transpose function transposes the rows and columns of its argument.
For example,
transpose [[1,2,3],[4,5,6]] == [[1,4],[2,5],[3,6]]
If some of the rows are shorter than the following rows, their elements are skipped:
transpose [[10,11],[20],[],[30,31,32]] == [[10,20,30],[11,31],[32]]
unfoldr :: (b -> Maybe (a, b)) -> b -> [a] #
The unfoldr function is a `dual' to foldr: while foldr
reduces a list to a summary value, unfoldr builds a list from
a seed value. The function takes the element and returns Nothing
if it is done producing the list or returns Just (a,b), in which
case, a is a prepended to the list and b is used as the next
element in a recursive call. For example,
iterate f == unfoldr (\x -> Just (x, f x))
In some cases, unfoldr can undo a foldr operation:
unfoldr f' (foldr f z xs) == xs
if the following holds:
f' (f x y) = Just (x,y) f' z = Nothing
A simple use of unfoldr:
unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10 [10,9,8,7,6,5,4,3,2,1]
unzip :: [(a, b)] -> ([a], [b]) #
unzip transforms a list of pairs into a list of first components
and a list of second components.
NonEmpty
Non-empty (and non-strict) list type.
Since: 4.9.0.0
Constructors
| a :| [a] infixr 5 |
Instances
| Monad NonEmpty | |
| Functor NonEmpty | |
| MonadFix NonEmpty | |
| Applicative NonEmpty | |
| Foldable NonEmpty | |
| Traversable NonEmpty | |
| Generic1 NonEmpty | |
| MonadZip NonEmpty | |
| IsList (NonEmpty a) | |
| Eq a => Eq (NonEmpty a) | |
| Data a => Data (NonEmpty a) | |
| Ord a => Ord (NonEmpty a) | |
| Read a => Read (NonEmpty a) | |
| Show a => Show (NonEmpty a) | |
| Generic (NonEmpty a) | |
| Semigroup (NonEmpty a) | |
| NFData a => NFData (NonEmpty a) | Since: 1.4.2.0 |
| Hashable a => Hashable (NonEmpty a) | |
| type Rep1 NonEmpty | |
| type Rep (NonEmpty a) | |
| type Item (NonEmpty a) | |
Tuple
uncurry :: (a -> b -> c) -> (a, b) -> c #
uncurry converts a curried function to a function on pairs.
Either
data Either a b :: * -> * -> * #
The Either type represents values with two possibilities: a value of
type is either Either a b or Left a.Right b
The Either type is sometimes used to represent a value which is
either correct or an error; by convention, the Left constructor is
used to hold an error value and the Right constructor is used to
hold a correct value (mnemonic: "right" also means "correct").
Examples
The type is the type of values which can be either
a Either String IntString or an Int. The Left constructor can be used only on
Strings, and the Right constructor can be used only on Ints:
>>>let s = Left "foo" :: Either String Int>>>sLeft "foo">>>let n = Right 3 :: Either String Int>>>nRight 3>>>:type ss :: Either String Int>>>:type nn :: Either String Int
The fmap from our Functor instance will ignore Left values, but
will apply the supplied function to values contained in a Right:
>>>let s = Left "foo" :: Either String Int>>>let n = Right 3 :: Either String Int>>>fmap (*2) sLeft "foo">>>fmap (*2) nRight 6
The Monad instance for Either allows us to chain together multiple
actions which may fail, and fail overall if any of the individual
steps failed. First we'll write a function that can either parse an
Int from a Char, or fail.
>>>import Data.Char ( digitToInt, isDigit )>>>:{let parseEither :: Char -> Either String Int parseEither c | isDigit c = Right (digitToInt c) | otherwise = Left "parse error">>>:}
The following should work, since both '1' and '2' can be
parsed as Ints.
>>>:{let parseMultiple :: Either String Int parseMultiple = do x <- parseEither '1' y <- parseEither '2' return (x + y)>>>:}
>>>parseMultipleRight 3
But the following should fail overall, since the first operation where
we attempt to parse 'm' as an Int will fail:
>>>:{let parseMultiple :: Either String Int parseMultiple = do x <- parseEither 'm' y <- parseEither '2' return (x + y)>>>:}
>>>parseMultipleLeft "parse error"
Instances
| Eq2 Either | |
| Ord2 Either | |
| Read2 Either | |
| Show2 Either | |
| Bifunctor Either | |
| Bitraversable Either | |
| Bifoldable Either | |
| Hashable2 Either | |
| MonadError e (Either e) | |
| Monad (Either e) | |
| Functor (Either a) | |
| MonadFix (Either e) | |
| Applicative (Either e) | |
| Foldable (Either a) | |
| Traversable (Either a) | |
| Generic1 (Either a) | |
| Eq a => Eq1 (Either a) | |
| Ord a => Ord1 (Either a) | |
| Read a => Read1 (Either a) | |
| Show a => Show1 (Either a) | |
| Hashable a => Hashable1 (Either a) | |
| (Eq b, Eq a) => Eq (Either a b) | |
| (Ord b, Ord a) => Ord (Either a b) | |
| (Read b, Read a) => Read (Either a b) | |
| (Show b, Show a) => Show (Either a b) | |
| Generic (Either a b) | |
| Semigroup (Either a b) | |
| (Binary a, Binary b) => Binary (Either a b) | |
| (NFData a, NFData b) => NFData (Either a b) | |
| (Hashable a, Hashable b) => Hashable (Either a b) | |
| type Rep1 (Either a) | |
| type Rep (Either a b) | |
| type (==) (Either k k1) a b | |
either :: (a -> c) -> (b -> c) -> Either a b -> c #
Case analysis for the Either type.
If the value is , apply the first function to Left aa;
if it is , apply the second function to Right bb.
Examples
We create two values of type , one using the
Either String IntLeft constructor and another using the Right constructor. Then
we apply "either" the length function (if we have a String)
or the "times-two" function (if we have an Int):
>>>let s = Left "foo" :: Either String Int>>>let n = Right 3 :: Either String Int>>>either length (*2) s3>>>either length (*2) n6
fromLeft :: a -> Either a b -> a #
Return the contents of a Left-value or a default value otherwise.
fromLeft 1 (Left 3) == 3 fromLeft 1 (Right "foo") == 1
fromRight :: b -> Either a b -> b #
Return the contents of a Right-value or a default value otherwise.
fromRight 1 (Right 3) == 3 fromRight 1 (Left "foo") == 1
isLeft :: Either a b -> Bool #
Return True if the given value is a Left-value, False otherwise.
Examples
Basic usage:
>>>isLeft (Left "foo")True>>>isLeft (Right 3)False
Assuming a Left value signifies some sort of error, we can use
isLeft to write a very simple error-reporting function that does
absolutely nothing in the case of success, and outputs "ERROR" if
any error occurred.
This example shows how isLeft might be used to avoid pattern
matching when one does not care about the value contained in the
constructor:
>>>import Control.Monad ( when )>>>let report e = when (isLeft e) $ putStrLn "ERROR">>>report (Right 1)>>>report (Left "parse error")ERROR
Since: 4.7.0.0
isRight :: Either a b -> Bool #
Return True if the given value is a Right-value, False otherwise.
Examples
Basic usage:
>>>isRight (Left "foo")False>>>isRight (Right 3)True
Assuming a Left value signifies some sort of error, we can use
isRight to write a very simple reporting function that only
outputs "SUCCESS" when a computation has succeeded.
This example shows how isRight might be used to avoid pattern
matching when one does not care about the value contained in the
constructor:
>>>import Control.Monad ( when )>>>let report e = when (isRight e) $ putStrLn "SUCCESS">>>report (Left "parse error")>>>report (Right 1)SUCCESS
Since: 4.7.0.0
partitionEithers :: [Either a b] -> ([a], [b]) #
Partitions a list of Either into two lists.
All the Left elements are extracted, in order, to the first
component of the output. Similarly the Right elements are extracted
to the second component of the output.
Examples
Basic usage:
>>>let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]>>>partitionEithers list(["foo","bar","baz"],[3,7])
The pair returned by should be the same
pair as partitionEithers x(:lefts x, rights x)
>>>let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]>>>partitionEithers list == (lefts list, rights list)True
eitherToMaybe :: Either a b -> Maybe b #
maybeToEither :: a -> Maybe b -> Either a b #
Text types
Char and String
The character type Char is an enumeration whose values represent
Unicode (or equivalently ISO/IEC 10646) characters (see
http://www.unicode.org/ for details). This set extends the ISO 8859-1
(Latin-1) character set (the first 256 characters), which is itself an extension
of the ASCII character set (the first 128 characters). A character literal in
Haskell has type Char.
To convert a Char to or from the corresponding Int value defined
by Unicode, use toEnum and fromEnum from the
Enum class respectively (or equivalently ord and chr).
Instances
| Bounded Char | |
| Enum Char | |
| Eq Char | |
| Ord Char | |
| Read Char | |
| Show Char | |
| Binary Char | |
| NFData Char | |
| Hashable Char | |
| ErrorList Char | |
| ConvertibleStrings String String | |
| ConvertibleStrings String StrictByteString | |
| ConvertibleStrings String LazyByteString | |
| ConvertibleStrings String StrictText | |
| ConvertibleStrings String LazyText | |
| ConvertibleStrings StrictByteString String | |
| ConvertibleStrings LazyByteString String | |
| ConvertibleStrings StrictText String | |
| ConvertibleStrings LazyText String | |
| Functor (URec Char) | |
| IsString (Seq Char) | |
| Foldable (URec Char) | |
| Traversable (URec Char) | |
| Generic1 (URec Char) | |
| Eq (URec Char p) | |
| Ord (URec Char p) | |
| Show (URec Char p) | |
| Generic (URec Char p) | |
| data URec Char | Used for marking occurrences of |
| type Rep1 (URec Char) | |
| type Rep (URec Char p) | |
Text
A space efficient, packed, unboxed Unicode text type.
Instances
ByteString
data ByteString :: * #
A space-efficient representation of a Word8 vector, supporting many
efficient operations.
A ByteString contains 8-bit bytes, or by using the operations from
Data.ByteString.Char8 it can be interpreted as containing 8-bit
characters.
Instances
type LByteString = ByteString Source #
Alias for lazy ByteString
Conversion
Class for string-like datastructures; used by the overloaded string extension (-XOverloadedStrings in GHC).
Minimal complete definition
Methods
fromString :: String -> a #
class ConvertibleStrings a b where #
Minimal complete definition
Methods
convertString :: a -> b #
Instances
Container types
Map and Set (Ordered)
A Map from keys k to values a.
Instances
| Functor (Map k) | |
| Foldable (Map k) | |
| Traversable (Map k) | |
| Ord k => IsList (Map k v) | |
| (Eq k, Eq a) => Eq (Map k a) | |
| (Data k, Data a, Ord k) => Data (Map k a) | |
| (Ord k, Ord v) => Ord (Map k v) | |
| (Ord k, Read k, Read e) => Read (Map k e) | |
| (Show k, Show a) => Show (Map k a) | |
| Ord k => Semigroup (Map k v) | |
| Ord k => Monoid (Map k v) | |
| (Binary k, Binary e) => Binary (Map k e) | |
| (NFData k, NFData a) => NFData (Map k a) | |
| type Item (Map k v) | |
A set of values a.
A map of integers to values a.
Instances
| Functor IntMap | |
| Foldable IntMap | |
| Traversable IntMap | |
| IsList (IntMap a) | |
| Eq a => Eq (IntMap a) | |
| Data a => Data (IntMap a) | |
| Ord a => Ord (IntMap a) | |
| Read e => Read (IntMap e) | |
| Show a => Show (IntMap a) | |
| Semigroup (IntMap a) | |
| Monoid (IntMap a) | |
| Binary e => Binary (IntMap e) | |
| NFData a => NFData (IntMap a) | |
| type Item (IntMap a) | |
A set of integers.
HashedMap and HashSet
data HashMap k v :: * -> * -> * #
A map from keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
Instances
| Functor (HashMap k) | |
| Foldable (HashMap k) | |
| Traversable (HashMap k) | |
| (Eq k, Hashable k) => IsList (HashMap k v) | |
| (Eq k, Eq v) => Eq (HashMap k v) | |
| (Data k, Data v, Eq k, Hashable k) => Data (HashMap k v) | |
| (Eq k, Hashable k, Read k, Read e) => Read (HashMap k e) | |
| (Show k, Show v) => Show (HashMap k v) | |
| (Eq k, Hashable k) => Semigroup (HashMap k v) | |
| (Eq k, Hashable k) => Monoid (HashMap k v) | |
| (NFData k, NFData v) => NFData (HashMap k v) | |
| (Hashable k, Hashable v) => Hashable (HashMap k v) | |
| type Item (HashMap k v) | |
A set of values. A set cannot contain duplicate values.
Instances
| Foldable HashSet | |
| (Eq a, Hashable a) => IsList (HashSet a) | |
| (Hashable a, Eq a) => Eq (HashSet a) | |
| (Data a, Eq a, Hashable a) => Data (HashSet a) | |
| (Eq a, Hashable a, Read a) => Read (HashSet a) | |
| Show a => Show (HashSet a) | |
| (Hashable a, Eq a) => Semigroup (HashSet a) | |
| (Hashable a, Eq a) => Monoid (HashSet a) | |
| NFData a => NFData (HashSet a) | |
| Hashable a => Hashable (HashSet a) | |
| type Item (HashSet a) | |
The class of types that can be converted to a hash value.
Minimal implementation: hashWithSalt.
Methods
hashWithSalt :: Int -> a -> Int infixl 0 #
Return a hash value for the argument, using the given salt.
The general contract of hashWithSalt is:
- If two values are equal according to the
==method, then applying thehashWithSaltmethod on each of the two values must produce the same integer result if the same salt is used in each case. - It is not required that if two values are unequal
according to the
==method, then applying thehashWithSaltmethod on each of the two values must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal values may improve the performance of hashing-based data structures. - This method can be used to compute different hash values for
the same input by providing a different salt in each
application of the method. This implies that any instance
that defines
hashWithSaltmust make use of the salt in its implementation.
Like hashWithSalt, but no salt is used. The default
implementation uses hashWithSalt with some default salt.
Instances might want to implement this method to provide a more
efficient implementation than the default implementation.
Instances
Instances
| Hashable1 [] | |
| Hashable1 Maybe | |
| Hashable1 Identity | |
| Hashable1 Fixed | |
| Hashable1 Hashed | |
| Hashable a => Hashable1 (Either a) | |
| Hashable a1 => Hashable1 ((,) a1) | |
| Hashable1 (Proxy *) | |
| (Hashable a1, Hashable a2) => Hashable1 ((,,) a1 a2) | |
| Hashable a => Hashable1 (Const * a) | |
| (Hashable a1, Hashable a2, Hashable a3) => Hashable1 ((,,,) a1 a2 a3) | |
| (Hashable1 f, Hashable1 g) => Hashable1 (Sum * f g) | |
| (Hashable1 f, Hashable1 g) => Hashable1 (Product * f g) | |
| (Hashable a1, Hashable a2, Hashable a3, Hashable a4) => Hashable1 ((,,,,) a1 a2 a3 a4) | |
| (Hashable1 f, Hashable1 g) => Hashable1 (Compose * * f g) | |
| (Hashable a1, Hashable a2, Hashable a3, Hashable a4, Hashable a5) => Hashable1 ((,,,,,) a1 a2 a3 a4 a5) | |
| (Hashable a1, Hashable a2, Hashable a3, Hashable a4, Hashable a5, Hashable a6) => Hashable1 ((,,,,,,) a1 a2 a3 a4 a5 a6) | |
Minimal complete definition
Instances
| Hashable2 Either | |
| Hashable2 (,) | |
| Hashable a1 => Hashable2 ((,,) a1) | |
| Hashable2 (Const *) | |
| (Hashable a1, Hashable a2) => Hashable2 ((,,,) a1 a2) | |
| (Hashable a1, Hashable a2, Hashable a3) => Hashable2 ((,,,,) a1 a2 a3) | |
| (Hashable a1, Hashable a2, Hashable a3, Hashable a4) => Hashable2 ((,,,,,) a1 a2 a3 a4) | |
| (Hashable a1, Hashable a2, Hashable a3, Hashable a4, Hashable a5) => Hashable2 ((,,,,,,) a1 a2 a3 a4 a5) | |
Seq
General-purpose finite sequences.
Instances
| Monad Seq | |
| Functor Seq | |
| Applicative Seq | |
| Foldable Seq | |
| Traversable Seq | |
| Alternative Seq | |
| MonadPlus Seq | |
| IsList (Seq a) | |
| Eq a => Eq (Seq a) | |
| Data a => Data (Seq a) | |
| Ord a => Ord (Seq a) | |
| Read a => Read (Seq a) | |
| Show a => Show (Seq a) | |
| IsString (Seq Char) | |
| Semigroup (Seq a) | |
| Monoid (Seq a) | |
| Binary e => Binary (Seq e) | |
| NFData a => NFData (Seq a) | |
| type Item (Seq a) | |
DList
A difference list is a function that, given a list, returns the original contents of the difference list prepended to the given list.
This structure supports O(1) append and snoc operations on lists, making it
very useful for append-heavy uses (esp. left-nested uses of ++), such
as logging and pretty printing.
Here is an example using DList as the state type when printing a tree with the Writer monad:
import Control.Monad.Writer
import Data.DList
data Tree a = Leaf a | Branch (Tree a) (Tree a)
flatten_writer :: Tree x -> DList x
flatten_writer = snd . runWriter . flatten
where
flatten (Leaf x) = tell (singleton x)
flatten (Branch x y) = flatten x >> flatten yInstances
| Monad DList | |
| Functor DList | |
| Applicative DList | |
| Foldable DList | |
| Alternative DList | |
| MonadPlus DList | |
| IsList (DList a) | |
| Eq a => Eq (DList a) | |
| Ord a => Ord (DList a) | |
| Read a => Read (DList a) | |
| Show a => Show (DList a) | |
| (~) * a Char => IsString (DList a) | |
| Semigroup (DList a) | |
| Monoid (DList a) | |
| NFData a => NFData (DList a) | |
| type Item (DList a) | |
Numeric types
Big integers
Type representing arbitrary-precision non-negative integers.
Operations whose result would be negative
.throw (Underflow :: ArithException)
Since: 4.8.0.0
Small integers
A fixed-precision integer type with at least the range [-2^29 .. 2^29-1].
The exact range for a given implementation can be determined by using
minBound and maxBound from the Bounded class.
Instances
| Bounded Int | |
| Enum Int | |
| Eq Int | |
| Integral Int | |
| Num Int | |
| Ord Int | |
| Read Int | |
| Real Int | |
| Show Int | |
| Bits Int | |
| FiniteBits Int | |
| Binary Int | |
| NFData Int | |
| Hashable Int | |
| Functor (URec Int) | |
| Foldable (URec Int) | |
| Traversable (URec Int) | |
| Generic1 (URec Int) | |
| Eq (URec Int p) | |
| Ord (URec Int p) | |
| Show (URec Int p) | |
| Generic (URec Int p) | |
| data URec Int | Used for marking occurrences of |
| type Rep1 (URec Int) | |
| type Rep (URec Int p) | |
8-bit signed integer type
16-bit signed integer type
32-bit signed integer type
64-bit signed integer type
Instances
| Bounded Word | |
| Enum Word | |
| Eq Word | |
| Integral Word | |
| Num Word | |
| Ord Word | |
| Read Word | |
| Real Word | |
| Show Word | |
| Bits Word | |
| FiniteBits Word | |
| Binary Word | |
| NFData Word | |
| Hashable Word | |
| Functor (URec Word) | |
| Foldable (URec Word) | |
| Traversable (URec Word) | |
| Generic1 (URec Word) | |
| Eq (URec Word p) | |
| Ord (URec Word p) | |
| Show (URec Word p) | |
| Generic (URec Word p) | |
| data URec Word | Used for marking occurrences of |
| type Rep1 (URec Word) | |
| type Rep (URec Word p) | |
8-bit unsigned integer type
16-bit unsigned integer type
32-bit unsigned integer type
64-bit unsigned integer type
Floating point
Single-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE single-precision type.
Instances
| Eq Float | |
| Floating Float | |
| Ord Float | |
| Read Float | |
| RealFloat Float | |
| Binary Float | |
| NFData Float | |
| Hashable Float | |
| Functor (URec Float) | |
| Foldable (URec Float) | |
| Traversable (URec Float) | |
| Generic1 (URec Float) | |
| Eq (URec Float p) | |
| Ord (URec Float p) | |
| Show (URec Float p) | |
| Generic (URec Float p) | |
| data URec Float | Used for marking occurrences of |
| type Rep1 (URec Float) | |
| type Rep (URec Float p) | |
Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.
Instances
| Eq Double | |
| Floating Double | |
| Ord Double | |
| Read Double | |
| RealFloat Double | |
| Binary Double | |
| NFData Double | |
| Hashable Double | |
| Functor (URec Double) | |
| Foldable (URec Double) | |
| Traversable (URec Double) | |
| Generic1 (URec Double) | |
| Eq (URec Double p) | |
| Ord (URec Double p) | |
| Show (URec Double p) | |
| Generic (URec Double p) | |
| data URec Double | Used for marking occurrences of |
| type Rep1 (URec Double) | |
| type Rep (URec Double p) | |
Rational
Rational numbers, with numerator and denominator of some Integral type.
Instances
| Integral a => Enum (Ratio a) | |
| Eq a => Eq (Ratio a) | |
| Integral a => Fractional (Ratio a) | |
| Integral a => Num (Ratio a) | |
| Integral a => Ord (Ratio a) | |
| (Integral a, Read a) => Read (Ratio a) | |
| Integral a => Real (Ratio a) | |
| Integral a => RealFrac (Ratio a) | |
| Show a => Show (Ratio a) | |
| (Binary a, Integral a) => Binary (Ratio a) | |
| NFData a => NFData (Ratio a) | |
| Hashable a => Hashable (Ratio a) | |
Extract the numerator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.
denominator :: Ratio a -> a #
Extract the denominator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.
approxRational :: RealFrac a => a -> a -> Rational #
approxRational, applied to two real fractional numbers x and epsilon,
returns the simplest rational number within epsilon of x.
A rational number y is said to be simpler than another y' if
, andabs(numeratory) <=abs(numeratory').denominatory <=denominatory'
Any real interval contains a unique simplest rational;
in particular, note that 0/1 is the simplest rational of all.
Numeric type classes
Num
Basic numeric class.
Methods
Unary negation.
Absolute value.
Sign of a number.
The functions abs and signum should satisfy the law:
abs x * signum x == x
For real numbers, the signum is either -1 (negative), 0 (zero)
or 1 (positive).
fromInteger :: Integer -> a #
Conversion from an Integer.
An integer literal represents the application of the function
fromInteger to the appropriate value of type Integer,
so such literals have type (.Num a) => a
Instances
| Num Int | |
| Num Int8 | |
| Num Int16 | |
| Num Int32 | |
| Num Int64 | |
| Num Integer | |
| Num Word | |
| Num Word8 | |
| Num Word16 | |
| Num Word32 | |
| Num Word64 | |
| Num Natural | |
| Integral a => Num (Ratio a) | |
| Num a => Num (Identity a) | |
| Num a => Num (Min a) | |
| Num a => Num (Max a) | |
| RealFloat a => Num (Complex a) | |
| Num a => Num (Sum a) | |
| Num a => Num (Product a) | |
| Num a => Num (Const k a b) | |
| Num (f a) => Num (Alt k f a) | |
| Num a => Num (Tagged k s a) | |
Real
class (Num a, Ord a) => Real a where #
Minimal complete definition
Methods
toRational :: a -> Rational #
the rational equivalent of its real argument with full precision
realToFrac :: (Real a, Fractional b) => a -> b #
general coercion to fractional types
Integral
class (Real a, Enum a) => Integral a where #
Integral numbers, supporting integer division.
Methods
quot :: a -> a -> a infixl 7 #
integer division truncated toward zero
integer remainder, satisfying
(x `quot` y)*y + (x `rem` y) == x
integer division truncated toward negative infinity
integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
conversion to Integer
Instances
fromIntegral :: (Integral a, Num b) => a -> b #
general coercion from integral types
Fractional
class Num a => Fractional a where #
Fractional numbers, supporting real division.
Minimal complete definition
fromRational, (recip | (/))
Methods
fractional division
reciprocal fraction
fromRational :: Rational -> a #
Conversion from a Rational (that is ).
A floating literal stands for an application of Ratio IntegerfromRational
to a value of type Rational, so such literals have type
(.Fractional a) => a
Instances
| Integral a => Fractional (Ratio a) | |
| Fractional a => Fractional (Identity a) | |
| RealFloat a => Fractional (Complex a) | |
| Fractional a => Fractional (Const k a b) | |
| Fractional a => Fractional (Tagged k s a) | |
(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 #
raise a number to an integral power
Floating
class Fractional a => Floating a where #
Trigonometric and hyperbolic functions and related functions.
Minimal complete definition
pi, exp, log, sin, cos, asin, acos, atan, sinh, cosh, asinh, acosh, atanh
RealFrac
class (Real a, Fractional a) => RealFrac a where #
Extracting components of fractions.
Minimal complete definition
Methods
properFraction :: Integral b => a -> (b, a) #
The function properFraction takes a real fractional number x
and returns a pair (n,f) such that x = n+f, and:
nis an integral number with the same sign asx; andfis a fraction with the same type and sign asx, and with absolute value less than1.
The default definitions of the ceiling, floor, truncate
and round functions are in terms of properFraction.
truncate :: Integral b => a -> b #
returns the integer nearest truncate xx between zero and x
round :: Integral b => a -> b #
returns the nearest integer to round xx;
the even integer if x is equidistant between two integers
ceiling :: Integral b => a -> b #
returns the least integer not less than ceiling xx
floor :: Integral b => a -> b #
returns the greatest integer not greater than floor xx
RealFloat
class (RealFrac a, Floating a) => RealFloat a where #
Efficient, machine-independent access to the components of a floating-point number.
Minimal complete definition
floatRadix, floatDigits, floatRange, decodeFloat, encodeFloat, isNaN, isInfinite, isDenormalized, isNegativeZero, isIEEE
Methods
floatRadix :: a -> Integer #
a constant function, returning the radix of the representation
(often 2)
floatDigits :: a -> Int #
a constant function, returning the number of digits of
floatRadix in the significand
floatRange :: a -> (Int, Int) #
a constant function, returning the lowest and highest values the exponent may assume
decodeFloat :: a -> (Integer, Int) #
The function decodeFloat applied to a real floating-point
number returns the significand expressed as an Integer and an
appropriately scaled exponent (an Int). If
yields decodeFloat x(m,n), then x is equal in value to m*b^^n, where b
is the floating-point radix, and furthermore, either m and n
are both zero or else b^(d-1) <= , where abs m < b^dd is
the value of .
In particular, floatDigits x. If the type
contains a negative zero, also decodeFloat 0 = (0,0).
The result of decodeFloat (-0.0) = (0,0) is unspecified if either of
decodeFloat x or isNaN x is isInfinite xTrue.
encodeFloat :: Integer -> Int -> a #
encodeFloat performs the inverse of decodeFloat in the
sense that for finite x with the exception of -0.0,
.
uncurry encodeFloat (decodeFloat x) = x is one of the two closest representable
floating-point numbers to encodeFloat m nm*b^^n (or ±Infinity if overflow
occurs); usually the closer, but if m contains too many bits,
the result may be rounded in the wrong direction.
exponent corresponds to the second component of decodeFloat.
and for finite nonzero exponent 0 = 0x,
.
If exponent x = snd (decodeFloat x) + floatDigits xx is a finite floating-point number, it is equal in value to
, where significand x * b ^^ exponent xb is the
floating-point radix.
The behaviour is unspecified on infinite or NaN values.
significand :: a -> a #
The first component of decodeFloat, scaled to lie in the open
interval (-1,1), either 0.0 or of absolute value >= 1/b,
where b is the floating-point radix.
The behaviour is unspecified on infinite or NaN values.
scaleFloat :: Int -> a -> a #
multiplies a floating-point number by an integer power of the radix
True if the argument is an IEEE "not-a-number" (NaN) value
isInfinite :: a -> Bool #
True if the argument is an IEEE infinity or negative infinity
isDenormalized :: a -> Bool #
True if the argument is too small to be represented in
normalized format
isNegativeZero :: a -> Bool #
True if the argument is an IEEE negative zero
True if the argument is an IEEE floating point number
a version of arctangent taking two real floating-point arguments.
For real floating x and y, computes the angle
(from the positive x-axis) of the vector from the origin to the
point atan2 y x(x,y). returns a value in the range [atan2 y x-pi,
pi]. It follows the Common Lisp semantics for the origin when
signed zeroes are supported. , with atan2 y 1y in a type
that is RealFloat, should return the same value as .
A default definition of atan yatan2 is provided, but implementors
can provide a more accurate implementation.
Bits
The Bits class defines bitwise operations over integral types.
- Bits are numbered from 0 with bit 0 being the least significant bit.
Minimal complete definition
(.&.), (.|.), xor, complement, (shift | shiftL, shiftR), (rotate | rotateL, rotateR), bitSize, bitSizeMaybe, isSigned, testBit, bit, popCount
Methods
(.&.) :: a -> a -> a infixl 7 #
Bitwise "and"
(.|.) :: a -> a -> a infixl 5 #
Bitwise "or"
Bitwise "xor"
complement :: a -> a #
Reverse all the bits in the argument
shift :: a -> Int -> a infixl 8 #
shifts shift x ix left by i bits if i is positive,
or right by -i bits otherwise.
Right shifts perform sign extension on signed number types;
i.e. they fill the top bits with 1 if the x is negative
and with 0 otherwise.
An instance can define either this unified shift or shiftL and
shiftR, depending on which is more convenient for the type in
question.
rotate :: a -> Int -> a infixl 8 #
rotates rotate x ix left by i bits if i is positive,
or right by -i bits otherwise.
For unbounded types like Integer, rotate is equivalent to shift.
An instance can define either this unified rotate or rotateL and
rotateR, depending on which is more convenient for the type in
question.
zeroBits is the value with all bits unset.
The following laws ought to hold (for all valid bit indices n):
clearBitzeroBitsn ==zeroBitssetBitzeroBitsn ==bitntestBitzeroBitsn == FalsepopCountzeroBits== 0
This method uses as its default
implementation (which ought to be equivalent to clearBit (bit 0) 0zeroBits for
types which possess a 0th bit).
Since: 4.7.0.0
bit i is a value with the ith bit set and all other bits clear.
Can be implemented using bitDefault if a is also an
instance of Num.
See also zeroBits.
x `setBit` i is the same as x .|. bit i
x `clearBit` i is the same as x .&. complement (bit i)
complementBit :: a -> Int -> a #
x `complementBit` i is the same as x `xor` bit i
Return True if the nth bit of the argument is 1
Can be implemented using testBitDefault if a is also an
instance of Num.
Return True if the argument is a signed type. The actual
value of the argument is ignored
rotateL :: a -> Int -> a infixl 8 #
Rotate the argument left by the specified number of bits (which must be non-negative).
An instance can define either this and rotateR or the unified
rotate, depending on which is more convenient for the type in
question.
rotateR :: a -> Int -> a infixl 8 #
Rotate the argument right by the specified number of bits (which must be non-negative).
An instance can define either this and rotateL or the unified
rotate, depending on which is more convenient for the type in
question.
Return the number of set bits in the argument. This number is known as the population count or the Hamming weight.
Can be implemented using popCountDefault if a is also an
instance of Num.
Since: 4.5.0.0
class Bits b => FiniteBits b where #
The FiniteBits class denotes types with a finite, fixed number of bits.
Since: 4.7.0.0
Minimal complete definition
Methods
finiteBitSize :: b -> Int #
Return the number of bits in the type of the argument.
The actual value of the argument is ignored. Moreover, finiteBitSize
is total, in contrast to the deprecated bitSize function it replaces.
finiteBitSize=bitSizebitSizeMaybe=Just.finiteBitSize
Since: 4.7.0.0
countLeadingZeros :: b -> Int #
Count number of zero bits preceding the most significant set bit.
countLeadingZeros(zeroBits:: a) = finiteBitSize (zeroBits:: a)
countLeadingZeros can be used to compute log base 2 via
logBase2 x =finiteBitSizex - 1 -countLeadingZerosx
Note: The default implementation for this method is intentionally naive. However, the instances provided for the primitive integral types are implemented using CPU specific machine instructions.
Since: 4.8.0.0
countTrailingZeros :: b -> Int #
Count number of zero bits following the least significant set bit.
countTrailingZeros(zeroBits:: a) = finiteBitSize (zeroBits:: a)countTrailingZeros.negate=countTrailingZeros
The related
find-first-set operation
can be expressed in terms of countTrailingZeros as follows
findFirstSet x = 1 + countTrailingZeros x
Note: The default implementation for this method is intentionally naive. However, the instances provided for the primitive integral types are implemented using CPU specific machine instructions.
Since: 4.8.0.0
Instances
| FiniteBits Bool | |
| FiniteBits Int | |
| FiniteBits Int8 | |
| FiniteBits Int16 | |
| FiniteBits Int32 | |
| FiniteBits Int64 | |
| FiniteBits Word | |
| FiniteBits Word8 | |
| FiniteBits Word16 | |
| FiniteBits Word32 | |
| FiniteBits Word64 | |
| FiniteBits a => FiniteBits (Identity a) | |
| FiniteBits a => FiniteBits (Const k a b) | |
| FiniteBits a => FiniteBits (Tagged k s a) | |
Read and Show
Show
Conversion of values to readable Strings.
Derived instances of Show have the following properties, which
are compatible with derived instances of Read:
- The result of
showis 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
showsPrecwill produce infix applications of the constructor. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
xis less thand(associativity is ignored). Thus, ifdis0then the result is never surrounded in parentheses; ifdis11it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then
showwill 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 = 5Note that right-associativity of :^: is ignored. For example,
produces the stringshow(Leaf 1 :^: Leaf 2 :^: Leaf 3)"Leaf 1 :^: (Leaf 2 :^: Leaf 3)".
Instances
Lifting of the Show class to unary type constructors.
Minimal complete definition
Instances
| Show1 [] | |
| Show1 Maybe | |
| Show1 Identity | |
| Show1 Hashed | |
| Show a => Show1 (Either a) | |
| Show a => Show1 ((,) a) | |
| Show1 (Proxy *) | Since: 4.9.0.0 |
| Show1 m => Show1 (MaybeT m) | |
| Show a => Show1 (Const * a) | |
| (Show e, Show1 m) => Show1 (ErrorT e m) | |
| (Show e, Show1 m) => Show1 (ExceptT e m) | |
| Show1 (Tagged k s) | |
| (Show1 f, Show1 g) => Show1 (Sum * f g) | |
| (Show1 f, Show1 g) => Show1 (Product * f g) | |
| (Show1 f, Show1 g) => Show1 (Compose * * f g) | |
Lifting of the Show class to binary type constructors.
Minimal complete definition
show :: (Show a, ConvertibleStrings String b) => a -> b Source #
Convert a value to a readable string type supported by ConvertibleStrings using the Show instance.
Read
Parsing of Strings, producing values.
Derived instances of Read make the following assumptions, which
derived instances of Show obey:
- If the constructor is defined to be an infix operator, then the
derived
Readinstance will parse only infix applications of the constructor (not the prefix form). - Associativity is not used to reduce the occurrence of parentheses, although precedence may be.
- If the constructor is defined using record syntax, the derived
Readwill parse only the record-syntax form, and furthermore, the fields must be given in the same order as the original declaration. - The derived
Readinstance allows arbitrary Haskell whitespace between tokens of the input string. Extra parentheses are also allowed.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Read in Haskell 2010 is equivalent to
instance (Read a) => Read (Tree a) where
readsPrec d r = readParen (d > app_prec)
(\r -> [(Leaf m,t) |
("Leaf",s) <- lex r,
(m,t) <- readsPrec (app_prec+1) s]) r
++ readParen (d > up_prec)
(\r -> [(u:^:v,w) |
(u,s) <- readsPrec (up_prec+1) r,
(":^:",t) <- lex s,
(v,w) <- readsPrec (up_prec+1) t]) r
where app_prec = 10
up_prec = 5Note that right-associativity of :^: is unused.
The derived instance in GHC is equivalent to
instance (Read a) => Read (Tree a) where
readPrec = parens $ (prec app_prec $ do
Ident "Leaf" <- lexP
m <- step readPrec
return (Leaf m))
+++ (prec up_prec $ do
u <- step readPrec
Symbol ":^:" <- lexP
v <- step readPrec
return (u :^: v))
where app_prec = 10
up_prec = 5
readListPrec = readListPrecDefaultInstances
| Read Bool | |
| Read Char | |
| Read Double | |
| Read Float | |
| Read Int | |
| Read Int8 | |
| Read Int16 | |
| Read Int32 | |
| Read Int64 | |
| Read Integer | |
| Read Ordering | |
| Read Word | |
| Read Word8 | |
| Read Word16 | |
| Read Word32 | |
| Read Word64 | |
| Read () | |
| Read Natural | |
| Read Void | Reading a |
| Read Version | |
| Read ExitCode | |
| Read All | |
| Read Any | |
| Read Fixity | |
| Read Associativity | |
| Read SourceUnpackedness | |
| Read SourceStrictness | |
| Read DecidedStrictness | |
| Read SomeNat | |
| Read SomeSymbol | |
| Read Lexeme | |
| Read GeneralCategory | |
| Read ByteString | |
| Read ByteString | |
| Read IntSet | |
| Read a => Read [a] | |
| Read a => Read (Maybe a) | |
| (Integral a, Read a) => Read (Ratio a) | |
| Read (V1 p) | |
| Read (U1 p) | |
| Read p => Read (Par1 p) | |
| Read a => Read (Identity a) | This instance would be equivalent to the derived instances of the
|
| Read a => Read (Min a) | |
| Read a => Read (Max a) | |
| Read a => Read (First a) | |
| Read a => Read (Last a) | |
| Read m => Read (WrappedMonoid m) | |
| Read a => Read (Option a) | |
| Read a => Read (NonEmpty a) | |
| Read a => Read (Complex a) | |
| Read a => Read (ZipList a) | |
| Read a => Read (Dual a) | |
| Read a => Read (Sum a) | |
| Read a => Read (Product a) | |
| Read a => Read (First a) | |
| Read a => Read (Last a) | |
| Read a => Read (Down a) | |
| Read e => Read (IntMap e) | |
| Read a => Read (Seq a) | |
| Read a => Read (ViewL a) | |
| Read a => Read (ViewR a) | |
| (Read a, Ord a) => Read (Set a) | |
| Read a => Read (DList a) | |
| (Eq a, Hashable a, Read a) => Read (HashSet a) | |
| (Read b, Read a) => Read (Either a b) | |
| Read (f p) => Read (Rec1 f p) | |
| (Read a, Read b) => Read (a, b) | |
| (Ix a, Read a, Read b) => Read (Array a b) | |
| (Read b, Read a) => Read (Arg a b) | |
| Read (Proxy k s) | |
| (Ord k, Read k, Read e) => Read (Map k e) | |
| (Read1 m, Read a) => Read (MaybeT m a) | |
| (Eq k, Hashable k, Read k, Read e) => Read (HashMap k e) | |
| Read c => Read (K1 i c p) | |
| (Read (g p), Read (f p)) => Read ((:+:) f g p) | |
| (Read (g p), Read (f p)) => Read ((:*:) f g p) | |
| Read (f (g p)) => Read ((:.:) f g p) | |
| (Read a, Read b, Read c) => Read (a, b, c) | |
| Read a => Read (Const k a b) | This instance would be equivalent to the derived instances of the
|
| Read (f a) => Read (Alt k f a) | |
| (~) k a b => Read ((:~:) k a b) | |
| (Read e, Read1 m, Read a) => Read (ErrorT e m a) | |
| (Read e, Read1 m, Read a) => Read (ExceptT e m a) | |
| Read b => Read (Tagged k s b) | |
| Read (f p) => Read (M1 i c f p) | |
| (Read a, Read b, Read c, Read d) => Read (a, b, c, d) | |
| (Read1 f, Read1 g, Read a) => Read (Sum * f g a) | |
| (Read1 f, Read1 g, Read a) => Read (Product * f g a) | |
| (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) | |
| (Read1 f, Read1 g, Read a) => Read (Compose * * f g a) | |
| (Read a, Read b, Read c, Read d, Read e, Read f) => Read (a, b, c, d, e, f) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g) => Read (a, b, c, d, e, f, g) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) => Read (a, b, c, d, e, f, g, h) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i) => Read (a, b, c, d, e, f, g, h, i) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j) => Read (a, b, c, d, e, f, g, h, i, j) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k) => Read (a, b, c, d, e, f, g, h, i, j, k) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l) => Read (a, b, c, d, e, f, g, h, i, j, k, l) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n, Read o) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | |
Lifting of the Read class to unary type constructors.
Minimal complete definition
Instances
| Read1 [] | |
| Read1 Maybe | |
| Read1 Identity | |
| Read a => Read1 (Either a) | |
| Read a => Read1 ((,) a) | |
| Read1 (Proxy *) | Since: 4.9.0.0 |
| Read1 m => Read1 (MaybeT m) | |
| Read a => Read1 (Const * a) | |
| (Read e, Read1 m) => Read1 (ErrorT e m) | |
| (Read e, Read1 m) => Read1 (ExceptT e m) | |
| Read1 (Tagged k s) | |
| (Read1 f, Read1 g) => Read1 (Sum * f g) | |
| (Read1 f, Read1 g) => Read1 (Product * f g) | |
| (Read1 f, Read1 g) => Read1 (Compose * * f g) | |
Lifting of the Read class to binary type constructors.
Minimal complete definition
readMaybe :: (Read b, ConvertibleStrings a String) => a -> Maybe b Source #
Parse a string type using the Read instance.
Succeeds if there is exactly one valid result.
Equality and Ordering
Eq
The Eq class defines equality (==) and inequality (/=).
All the basic datatypes exported by the Prelude are instances of Eq,
and Eq may be derived for any datatype whose constituents are also
instances of Eq.
Instances
| Eq Bool | |
| Eq Char | |
| Eq Double | |
| Eq Float | |
| Eq Int | |
| Eq Int8 | |
| Eq Int16 | |
| Eq Int32 | |
| Eq Int64 | |
| Eq Integer | |
| Eq Ordering | |
| Eq Word | |
| Eq Word8 | |
| Eq Word16 | |
| Eq Word32 | |
| Eq Word64 | |
| Eq TypeRep | |
| Eq () | |
| Eq TyCon | |
| Eq BigNat | |
| Eq SpecConstrAnnotation | |
| Eq Natural | |
| Eq Void | |
| Eq Version | |
| Eq AsyncException | |
| Eq ArrayException | |
| Eq ExitCode | |
| Eq IOErrorType | |
| Eq All | |
| Eq Any | |
| Eq Fixity | |
| Eq Associativity | |
| Eq SourceUnpackedness | |
| Eq SourceStrictness | |
| Eq DecidedStrictness | |
| Eq MaskingState | |
| Eq IOException | |
| Eq ErrorCall | |
| Eq ArithException | |
| Eq SomeNat | |
| Eq SomeSymbol | |
| Eq SrcLoc | |
| Eq ByteString | |
| Eq ByteString | |
| Eq IntSet | |
| Eq a => Eq [a] | |
| Eq a => Eq (Maybe a) | |
| Eq a => Eq (Ratio a) | |
| Eq (Ptr a) | |
| Eq (FunPtr a) | |
| Eq (V1 p) | |
| Eq (U1 p) | |
| Eq p => Eq (Par1 p) | |
| Eq (ForeignPtr a) | |
| Eq a => Eq (Identity a) | |
| Eq a => Eq (Min a) | |
| Eq a => Eq (Max a) | |
| Eq a => Eq (First a) | |
| Eq a => Eq (Last a) | |
| Eq m => Eq (WrappedMonoid m) | |
| Eq a => Eq (Option a) | |
| Eq a => Eq (NonEmpty a) | |
| Eq a => Eq (Complex a) | |
| Eq a => Eq (ZipList a) | |
| Eq a => Eq (Dual a) | |
| Eq a => Eq (Sum a) | |
| Eq a => Eq (Product a) | |
| Eq a => Eq (First a) | |
| Eq a => Eq (Last a) | |
| Eq a => Eq (Down a) | |
| Eq a => Eq (IntMap a) | |
| Eq a => Eq (Seq a) | |
| Eq a => Eq (ViewL a) | |
| Eq a => Eq (ViewR a) | |
| Eq a => Eq (Set a) | |
| Eq a => Eq (DList a) | |
| Eq a => Eq (Hashed a) | Uses precomputed hash to detect inequality faster |
| (Hashable a, Eq a) => Eq (HashSet a) | |
| (Eq b, Eq a) => Eq (Either a b) | |
| Eq (f p) => Eq (Rec1 f p) | |
| Eq (URec Char p) | |
| Eq (URec Double p) | |
| Eq (URec Float p) | |
| Eq (URec Int p) | |
| Eq (URec Word p) | |
| Eq (URec (Ptr ()) p) | |
| (Eq a, Eq b) => Eq (a, b) | |
| Eq a => Eq (Arg a b) | |
| Eq (Proxy k s) | |
| (Eq k, Eq a) => Eq (Map k a) | |
| (Eq1 m, Eq a) => Eq (MaybeT m a) | |
| (Eq v, Eq k) => Eq (Leaf k v) | |
| (Eq k, Eq v) => Eq (HashMap k v) | |
| Eq c => Eq (K1 i c p) | |
| (Eq (g p), Eq (f p)) => Eq ((:+:) f g p) | |
| (Eq (g p), Eq (f p)) => Eq ((:*:) f g p) | |
| Eq (f (g p)) => Eq ((:.:) f g p) | |
| (Eq a, Eq b, Eq c) => Eq (a, b, c) | |
| Eq a => Eq (Const k a b) | |
| Eq (f a) => Eq (Alt k f a) | |
| Eq ((:~:) k a b) | |
| (Eq e, Eq1 m, Eq a) => Eq (ErrorT e m a) | |
| (Eq e, Eq1 m, Eq a) => Eq (ExceptT e m a) | |
| Eq b => Eq (Tagged k s b) | |
| Eq (f p) => Eq (M1 i c f p) | |
| (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) | |
| (Eq1 f, Eq1 g, Eq a) => Eq (Sum * f g a) | |
| (Eq1 f, Eq1 g, Eq a) => Eq (Product * f g a) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e) | |
| (Eq1 f, Eq1 g, Eq a) => Eq (Compose * * f g a) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | |
Lifting of the Eq class to unary type constructors.
Minimal complete definition
Instances
| Eq1 [] | |
| Eq1 Maybe | |
| Eq1 Identity | |
| Eq1 Hashed | |
| Eq a => Eq1 (Either a) | |
| Eq a => Eq1 ((,) a) | |
| Eq1 (Proxy *) | Since: 4.9.0.0 |
| Eq1 m => Eq1 (MaybeT m) | |
| Eq a => Eq1 (Const * a) | |
| (Eq e, Eq1 m) => Eq1 (ErrorT e m) | |
| (Eq e, Eq1 m) => Eq1 (ExceptT e m) | |
| Eq1 (Tagged k s) | |
| (Eq1 f, Eq1 g) => Eq1 (Sum * f g) | |
| (Eq1 f, Eq1 g) => Eq1 (Product * f g) | |
| (Eq1 f, Eq1 g) => Eq1 (Compose * * f g) | |
Lifting of the Eq class to binary type constructors.
Minimal complete definition
Ord
The Ord class is used for totally ordered datatypes.
Instances of Ord can be derived for any user-defined
datatype whose constituent types are in Ord. The declared order
of the constructors in the data declaration determines the ordering
in derived Ord instances. The Ordering datatype allows a single
comparison to determine the precise ordering of two objects.
Minimal complete definition: either compare or <=.
Using compare can be more efficient for complex types.
Methods
compare :: a -> a -> Ordering #
(<) :: a -> a -> Bool infix 4 #
(<=) :: a -> a -> Bool infix 4 #
(>) :: a -> a -> Bool infix 4 #
Instances
| Ord Bool | |
| Ord Char | |
| Ord Double | |
| Ord Float | |
| Ord Int | |
| Ord Int8 | |
| Ord Int16 | |
| Ord Int32 | |
| Ord Int64 | |
| Ord Integer | |
| Ord Ordering | |
| Ord Word | |
| Ord Word8 | |
| Ord Word16 | |
| Ord Word32 | |
| Ord Word64 | |
| Ord TypeRep | |
| Ord () | |
| Ord TyCon | |
| Ord BigNat | |
| Ord Natural | |
| Ord Void | |
| Ord Version | |
| Ord AsyncException | |
| Ord ArrayException | |
| Ord ExitCode | |
| Ord All | |
| Ord Any | |
| Ord Fixity | |
| Ord Associativity | |
| Ord SourceUnpackedness | |
| Ord SourceStrictness | |
| Ord DecidedStrictness | |
| Ord ErrorCall | |
| Ord ArithException | |
| Ord SomeNat | |
| Ord SomeSymbol | |
| Ord ByteString | |
| Ord ByteString | |
| Ord IntSet | |
| Ord a => Ord [a] | |
| Ord a => Ord (Maybe a) | |
| Integral a => Ord (Ratio a) | |
| Ord (Ptr a) | |
| Ord (FunPtr a) | |
| Ord (V1 p) | |
| Ord (U1 p) | |
| Ord p => Ord (Par1 p) | |
| Ord (ForeignPtr a) | |
| Ord a => Ord (Identity a) | |
| Ord a => Ord (Min a) | |
| Ord a => Ord (Max a) | |
| Ord a => Ord (First a) | |
| Ord a => Ord (Last a) | |
| Ord m => Ord (WrappedMonoid m) | |
| Ord a => Ord (Option a) | |
| Ord a => Ord (NonEmpty a) | |
| Ord a => Ord (ZipList a) | |
| Ord a => Ord (Dual a) | |
| Ord a => Ord (Sum a) | |
| Ord a => Ord (Product a) | |
| Ord a => Ord (First a) | |
| Ord a => Ord (Last a) | |
| Ord a => Ord (Down a) | |
| Ord a => Ord (IntMap a) | |
| Ord a => Ord (Seq a) | |
| Ord a => Ord (ViewL a) | |
| Ord a => Ord (ViewR a) | |
| Ord a => Ord (Set a) | |
| Ord a => Ord (DList a) | |
| Ord a => Ord (Hashed a) | |
| (Ord b, Ord a) => Ord (Either a b) | |
| Ord (f p) => Ord (Rec1 f p) | |
| Ord (URec Char p) | |
| Ord (URec Double p) | |
| Ord (URec Float p) | |
| Ord (URec Int p) | |
| Ord (URec Word p) | |
| Ord (URec (Ptr ()) p) | |
| (Ord a, Ord b) => Ord (a, b) | |
| Ord a => Ord (Arg a b) | |
| Ord (Proxy k s) | |
| (Ord k, Ord v) => Ord (Map k v) | |
| (Ord1 m, Ord a) => Ord (MaybeT m a) | |
| Ord c => Ord (K1 i c p) | |
| (Ord (g p), Ord (f p)) => Ord ((:+:) f g p) | |
| (Ord (g p), Ord (f p)) => Ord ((:*:) f g p) | |
| Ord (f (g p)) => Ord ((:.:) f g p) | |
| (Ord a, Ord b, Ord c) => Ord (a, b, c) | |
| Ord a => Ord (Const k a b) | |
| Ord (f a) => Ord (Alt k f a) | |
| Ord ((:~:) k a b) | |
| (Ord e, Ord1 m, Ord a) => Ord (ErrorT e m a) | |
| (Ord e, Ord1 m, Ord a) => Ord (ExceptT e m a) | |
| Ord b => Ord (Tagged k s b) | |
| Ord (f p) => Ord (M1 i c f p) | |
| (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d) | |
| (Ord1 f, Ord1 g, Ord a) => Ord (Sum * f g a) | |
| (Ord1 f, Ord1 g, Ord a) => Ord (Product * f g a) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e) | |
| (Ord1 f, Ord1 g, Ord a) => Ord (Compose * * f g a) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) => Ord (a, b, c, d, e, f) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g) => Ord (a, b, c, d, e, f, g) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h) => Ord (a, b, c, d, e, f, g, h) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i) => Ord (a, b, c, d, e, f, g, h, i) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j) => Ord (a, b, c, d, e, f, g, h, i, j) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k) => Ord (a, b, c, d, e, f, g, h, i, j, k) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l) => Ord (a, b, c, d, e, f, g, h, i, j, k, l) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | |
Lifting of the Ord class to unary type constructors.
Minimal complete definition
Instances
| Ord1 [] | |
| Ord1 Maybe | |
| Ord1 Identity | |
| Ord1 Hashed | |
| Ord a => Ord1 (Either a) | |
| Ord a => Ord1 ((,) a) | |
| Ord1 (Proxy *) | Since: 4.9.0.0 |
| Ord1 m => Ord1 (MaybeT m) | |
| Ord a => Ord1 (Const * a) | |
| (Ord e, Ord1 m) => Ord1 (ErrorT e m) | |
| (Ord e, Ord1 m) => Ord1 (ExceptT e m) | |
| Ord1 (Tagged k s) | |
| (Ord1 f, Ord1 g) => Ord1 (Sum * f g) | |
| (Ord1 f, Ord1 g) => Ord1 (Product * f g) | |
| (Ord1 f, Ord1 g) => Ord1 (Compose * * f g) | |
Lifting of the Ord class to binary type constructors.
Minimal complete definition
The Down type allows you to reverse sort order conveniently. A value of type
contains a value of type Down aa (represented as ).
If Down aa has an instance associated with it then comparing two
values thus wrapped will give you the opposite of their normal sort order.
This is particularly useful when sorting in generalised list comprehensions,
as in: Ordthen sortWith by Down x
Provides Show and Read instances (since: 4.7.0.0).
Since: 4.6.0.0
Constructors
| Down a |
comparing :: Ord a => (b -> a) -> b -> b -> Ordering #
comparing p x y = compare (p x) (p y)
Useful combinator for use in conjunction with the xxxBy family
of functions from Data.List, for example:
... sortBy (comparing fst) ...
Enum
Class Enum defines operations on sequentially ordered types.
The enumFrom... methods are used in Haskell's translation of
arithmetic sequences.
Instances of Enum may be derived for any enumeration type (types
whose constructors have no fields). The nullary constructors are
assumed to be numbered left-to-right by fromEnum from 0 through n-1.
See Chapter 10 of the Haskell Report for more details.
For any type that is an instance of class Bounded as well as Enum,
the following should hold:
- The calls
andsuccmaxBoundshould result in a runtime error.predminBound fromEnumandtoEnumshould give a runtime error if the result value is not representable in the result type. For example,is an error.toEnum7 ::BoolenumFromandenumFromThenshould be defined with an implicit bound, thus:
enumFrom x = enumFromTo x maxBound
enumFromThen x y = enumFromThenTo x y bound
where
bound | fromEnum y >= fromEnum x = maxBound
| otherwise = minBoundMethods
Convert to an Int.
It is implementation-dependent what fromEnum returns when
applied to a value that is too large to fit in an Int.
Used in Haskell's translation of [n..].
enumFromThen :: a -> a -> [a] #
Used in Haskell's translation of [n,n'..].
enumFromTo :: a -> a -> [a] #
Used in Haskell's translation of [n..m].
enumFromThenTo :: a -> a -> a -> [a] #
Used in Haskell's translation of [n,n'..m].
Instances
| Enum Bool | |
| Enum Char | |
| Enum Int | |
| Enum Int8 | |
| Enum Int16 | |
| Enum Int32 | |
| Enum Int64 | |
| Enum Integer | |
| Enum Ordering | |
| Enum Word | |
| Enum Word8 | |
| Enum Word16 | |
| Enum Word32 | |
| Enum Word64 | |
| Enum () | |
| Enum Natural | |
| Enum Associativity | |
| Enum SourceUnpackedness | |
| Enum SourceStrictness | |
| Enum DecidedStrictness | |
| Integral a => Enum (Ratio a) | |
| Enum a => Enum (Identity a) | |
| Enum a => Enum (Min a) | |
| Enum a => Enum (Max a) | |
| Enum a => Enum (First a) | |
| Enum a => Enum (Last a) | |
| Enum a => Enum (WrappedMonoid a) | |
| Enum (Proxy k s) | |
| Enum a => Enum (Const k a b) | |
| Enum (f a) => Enum (Alt k f a) | |
| (~) k a b => Enum ((:~:) k a b) | |
| Enum a => Enum (Tagged k s a) | |
Bounded
The Bounded class is used to name the upper and lower limits of a
type. Ord is not a superclass of Bounded since types that are not
totally ordered may also have upper and lower bounds.
The Bounded class may be derived for any enumeration type;
minBound is the first constructor listed in the data declaration
and maxBound is the last.
Bounded may also be derived for single-constructor datatypes whose
constituent types are in Bounded.
Instances
Algebraic type classes
Category
A class for categories. id and (.) must form a monoid.
Semigroup
The class of semigroups (types with an associative binary operation).
Since: 4.9.0.0
Methods
(<>) :: a -> a -> a infixr 6 #
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.
stimes :: Integral b => b -> a -> a #
Repeat a value n times.
Given that this works on a Semigroup it is allowed to fail if
you request 0 or fewer repetitions, and the default definition
will do so.
By making this a member of the class, idempotent semigroups and monoids can
upgrade this to execute in O(1) by picking
stimes = stimesIdempotent or stimes = stimesIdempotentMonoid
respectively.
Instances
Use to get the behavior of
Option (First a)First from Data.Monoid.
Instances
| Monad First | |
| Functor First | |
| MonadFix First | |
| Applicative First | |
| Foldable First | |
| Traversable First | |
| Generic1 First | |
| Bounded a => Bounded (First a) | |
| Enum a => Enum (First a) | |
| Eq a => Eq (First a) | |
| Data a => Data (First a) | |
| Ord a => Ord (First a) | |
| Read a => Read (First a) | |
| Show a => Show (First a) | |
| Generic (First a) | |
| Semigroup (First a) | |
| NFData a => NFData (First a) | Since: 1.4.2.0 |
| Hashable a => Hashable (First a) | |
| type Rep1 First | |
| type Rep (First a) | |
Use to get the behavior of
Option (Last a)Last from Data.Monoid
Instances
| Monad Last | |
| Functor Last | |
| MonadFix Last | |
| Applicative Last | |
| Foldable Last | |
| Traversable Last | |
| Generic1 Last | |
| Bounded a => Bounded (Last a) | |
| Enum a => Enum (Last a) | |
| Eq a => Eq (Last a) | |
| Data a => Data (Last a) | |
| Ord a => Ord (Last a) | |
| Read a => Read (Last a) | |
| Show a => Show (Last a) | |
| Generic (Last a) | |
| Semigroup (Last a) | |
| NFData a => NFData (Last a) | Since: 1.4.2.0 |
| Hashable a => Hashable (Last a) | |
| type Rep1 Last | |
| type Rep (Last a) | |
Instances
| Monad Min | |
| Functor Min | |
| MonadFix Min | |
| Applicative Min | |
| Foldable Min | |
| Traversable Min | |
| Generic1 Min | |
| Bounded a => Bounded (Min a) | |
| Enum a => Enum (Min a) | |
| Eq a => Eq (Min a) | |
| Data a => Data (Min a) | |
| Num a => Num (Min a) | |
| Ord a => Ord (Min a) | |
| Read a => Read (Min a) | |
| Show a => Show (Min a) | |
| Generic (Min a) | |
| Ord a => Semigroup (Min a) | |
| (Ord a, Bounded a) => Monoid (Min a) | |
| NFData a => NFData (Min a) | Since: 1.4.2.0 |
| Hashable a => Hashable (Min a) | |
| type Rep1 Min | |
| type Rep (Min a) | |
Instances
| Monad Max | |
| Functor Max | |
| MonadFix Max | |
| Applicative Max | |
| Foldable Max | |
| Traversable Max | |
| Generic1 Max | |
| Bounded a => Bounded (Max a) | |
| Enum a => Enum (Max a) | |
| Eq a => Eq (Max a) | |
| Data a => Data (Max a) | |
| Num a => Num (Max a) | |
| Ord a => Ord (Max a) | |
| Read a => Read (Max a) | |
| Show a => Show (Max a) | |
| Generic (Max a) | |
| Ord a => Semigroup (Max a) | |
| (Ord a, Bounded a) => Monoid (Max a) | |
| NFData a => NFData (Max a) | Since: 1.4.2.0 |
| Hashable a => Hashable (Max a) | |
| type Rep1 Max | |
| type Rep (Max a) | |
Option is effectively Maybe with a better instance of
Monoid, built off of an underlying Semigroup instead of an
underlying Monoid.
Ideally, this type would not exist at all and we would just fix the
Monoid instance of Maybe
Instances
| Monad Option | |
| Functor Option | |
| MonadFix Option | |
| Applicative Option | |
| Foldable Option | |
| Traversable Option | |
| Generic1 Option | |
| Alternative Option | |
| MonadPlus Option | |
| Eq a => Eq (Option a) | |
| Data a => Data (Option a) | |
| Ord a => Ord (Option a) | |
| Read a => Read (Option a) | |
| Show a => Show (Option a) | |
| Generic (Option a) | |
| Semigroup a => Semigroup (Option a) | |
| Semigroup a => Monoid (Option a) | |
| NFData a => NFData (Option a) | Since: 1.4.2.0 |
| Hashable a => Hashable (Option a) | |
| type Rep1 Option | |
| type Rep (Option a) | |
Monoid
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:
mappend mempty x = x
mappend x mempty = x
mappend x (mappend y z) = mappend (mappend x y) z
mconcat =
foldrmappend mempty
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtypes and make those instances
of Monoid, e.g. Sum and Product.
Methods
Identity of mappend
An associative operation
Fold a list using the monoid.
For most types, the default definition for mconcat will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
Instances
| Monoid Ordering | |
| Monoid () | |
| Monoid All | |
| Monoid Any | |
| Monoid ByteString | |
| Monoid ByteString | |
| Monoid IntSet | |
| Monoid [a] | |
| Monoid a => Monoid (Maybe a) | Lift a semigroup into |
| Monoid a => Monoid (IO a) | |
| Ord a => Monoid (Max a) | |
| Ord a => Monoid (Min a) | |
| Monoid a => Monoid (Identity a) | |
| (Ord a, Bounded a) => Monoid (Min a) | |
| (Ord a, Bounded a) => Monoid (Max a) | |
| Monoid m => Monoid (WrappedMonoid m) | |
| Semigroup a => Monoid (Option a) | |
| Monoid a => Monoid (Dual a) | |
| Monoid (Endo a) | |
| Num a => Monoid (Sum a) | |
| Num a => Monoid (Product a) | |
| Monoid (First a) | |
| Monoid (Last a) | |
| Ord a => Monoid (Max a) | |
| Ord a => Monoid (Min a) | |
| Monoid (IntMap a) | |
| Monoid (Seq a) | |
| Ord a => Monoid (Set a) | |
| Monoid (DList a) | |
| (Hashable a, Eq a) => Monoid (HashSet a) | |
| Monoid b => Monoid (a -> b) | |
| (Monoid a, Monoid b) => Monoid (a, b) | |
| Monoid (Proxy k s) | |
| Ord k => Monoid (Map k v) | |
| (Eq k, Hashable k) => Monoid (HashMap k v) | |
| (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | |
| Monoid a => Monoid (Const k a b) | |
| Alternative f => Monoid (Alt * f a) | |
| (Semigroup a, Monoid a) => Monoid (Tagged k s a) | |
| (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | |
| (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) | |
Instances
| Monad Dual | |
| Functor Dual | |
| MonadFix Dual | |
| Applicative Dual | |
| Foldable Dual | |
| Traversable Dual | |
| Generic1 Dual | |
| Bounded a => Bounded (Dual a) | |
| Eq a => Eq (Dual a) | |
| Ord a => Ord (Dual a) | |
| Read a => Read (Dual a) | |
| Show a => Show (Dual a) | |
| Generic (Dual a) | |
| Semigroup a => Semigroup (Dual a) | |
| Monoid a => Monoid (Dual a) | |
| NFData a => NFData (Dual a) | Since: 1.4.0.0 |
| type Rep1 Dual | |
| type Rep (Dual a) | |
The monoid of endomorphisms under composition.
Boolean monoid under conjunction (&&).
Boolean monoid under disjunction (||).
newtype Alt k f a :: forall k. (k -> *) -> k -> * #
Monoid under <|>.
Since: 4.8.0.0
Instances
| Monad f => Monad (Alt * f) | |
| Functor f => Functor (Alt * f) | |
| MonadFix f => MonadFix (Alt * f) | |
| Applicative f => Applicative (Alt * f) | |
| Generic1 (Alt * f) | |
| Alternative f => Alternative (Alt * f) | |
| MonadPlus f => MonadPlus (Alt * f) | |
| Enum (f a) => Enum (Alt k f a) | |
| Eq (f a) => Eq (Alt k f a) | |
| Num (f a) => Num (Alt k f a) | |
| Ord (f a) => Ord (Alt k f a) | |
| Read (f a) => Read (Alt k f a) | |
| Show (f a) => Show (Alt k f a) | |
| Generic (Alt k f a) | |
| Alternative f => Semigroup (Alt * f a) | |
| Alternative f => Monoid (Alt * f a) | |
| type Rep1 (Alt * f) | |
| type Rep (Alt k f a) | |
Functor
The Functor class is used for types that can be mapped over.
Instances of Functor should satisfy the following laws:
fmap id == id fmap (f . g) == fmap f . fmap g
The instances of Functor for lists, Maybe and IO
satisfy these laws.
Minimal complete definition
Methods
Instances
($>) :: Functor f => f a -> b -> f b infixl 4 #
Flipped version of <$.
Examples
Replace the contents of a with a constant Maybe IntString:
>>>Nothing $> "foo"Nothing>>>Just 90210 $> "foo"Just "foo"
Replace the contents of an with a constant
Either Int IntString, resulting in an :Either Int String
>>>Left 8675309 $> "foo"Left 8675309>>>Right 8675309 $> "foo"Right "foo"
Replace each element of a list with a constant String:
>>>[1,2,3] $> "foo"["foo","foo","foo"]
Replace the second element of a pair with a constant String:
>>>(1,2) $> "foo"(1,"foo")
Since: 4.7.0.0
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap.
The name of this operator is an allusion to $.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $ is function application, <$> is function
application lifted over a Functor.
Examples
Convert from a to a Maybe Int using Maybe Stringshow:
>>>show <$> NothingNothing>>>show <$> Just 3Just "3"
Convert from an to an Either Int IntEither IntString using show:
>>>show <$> Left 17Left 17>>>show <$> Right 17Right "17"
Double each element of a list:
>>>(*2) <$> [1,2,3][2,4,6]
Apply even to the second element of a pair:
>>>even <$> (2,2)(2,True)
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void valueIO action.
Examples
Replace the contents of a with unit:Maybe Int
>>>void NothingNothing>>>void (Just 3)Just ()
Replace the contents of an with unit,
resulting in an Either Int Int:Either Int '()'
>>>void (Left 8675309)Left 8675309>>>void (Right 8675309)Right ()
Replace every element of a list with unit:
>>>void [1,2,3][(),(),()]
Replace the second element of a pair with unit:
>>>void (1,2)(1,())
Discard the result of an IO action:
>>>mapM print [1,2]1 2 [(),()]>>>void $ mapM print [1,2]1 2
newtype Const k a b :: forall k. * -> k -> * #
The Const functor.
Instances
| Eq2 (Const *) | |
| Ord2 (Const *) | |
| Read2 (Const *) | |
| Show2 (Const *) | |
| Bifunctor (Const *) | |
| Bitraversable (Const *) | |
| Bifoldable (Const *) | |
| Hashable2 (Const *) | |
| Functor (Const * m) | |
| Monoid m => Applicative (Const * m) | |
| Foldable (Const * m) | |
| Traversable (Const * m) | |
| Generic1 (Const * a) | |
| Eq a => Eq1 (Const * a) | |
| Ord a => Ord1 (Const * a) | |
| Read a => Read1 (Const * a) | |
| Show a => Show1 (Const * a) | |
| Hashable a => Hashable1 (Const * a) | |
| Bounded a => Bounded (Const k a b) | |
| Enum a => Enum (Const k a b) | |
| Eq a => Eq (Const k a b) | |
| Floating a => Floating (Const k a b) | |
| Fractional a => Fractional (Const k a b) | |
| Integral a => Integral (Const k a b) | |
| Num a => Num (Const k a b) | |
| Ord a => Ord (Const k a b) | |
| Read a => Read (Const k a b) | This instance would be equivalent to the derived instances of the
|
| Real a => Real (Const k a b) | |
| RealFloat a => RealFloat (Const k a b) | |
| RealFrac a => RealFrac (Const k a b) | |
| Show a => Show (Const k a b) | This instance would be equivalent to the derived instances of the
|
| Ix a => Ix (Const k a b) | |
| IsString a => IsString (Const * a b) | |
| Generic (Const k a b) | |
| Semigroup a => Semigroup (Const k a b) | |
| Monoid a => Monoid (Const k a b) | |
| Storable a => Storable (Const k a b) | |
| Bits a => Bits (Const k a b) | |
| FiniteBits a => FiniteBits (Const k a b) | |
| NFData a => NFData (Const k a b) | Since: 1.4.0.0 |
| Hashable a => Hashable (Const * a b) | |
| type Rep1 (Const * a) | |
| type Rep (Const k a b) | |
newtype Identity a :: * -> * #
Identity functor and monad. (a non-strict monad)
Since: 4.8.0.0
Constructors
| Identity | |
Fields
| |
Instances
Foldable
Data structures that can be folded.
For example, given a data type
data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
a suitable instance would be
instance Foldable Tree where foldMap f Empty = mempty foldMap f (Leaf x) = f x foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r
This is suitable even for abstract types, as the monoid is assumed
to satisfy the monoid laws. Alternatively, one could define foldr:
instance Foldable Tree where foldr f z Empty = z foldr f z (Leaf x) = f x z foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l
Foldable instances are expected to satisfy the following laws:
foldr f z t = appEndo (foldMap (Endo . f) t ) z
foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z
fold = foldMap id
sum, product, maximum, and minimum should all be essentially
equivalent to foldMap forms, such as
sum = getSum . foldMap Sum
but may be less defined.
If the type is also a Functor instance, it should satisfy
foldMap f = fold . fmap f
which implies that
foldMap f . fmap g = foldMap (f . g)
Methods
fold :: Monoid m => t m -> m #
Combine the elements of a structure using a monoid.
foldMap :: Monoid m => (a -> m) -> t a -> m #
Map each element of the structure to a monoid, and combine the results.
foldr :: (a -> b -> b) -> b -> t a -> b #
Right-associative fold of a structure.
In the case of lists, foldr, when applied to a binary operator, a
starting value (typically the right-identity of the operator), and a
list, reduces the list using the binary operator, from right to left:
foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
Note that, since the head of the resulting expression is produced by
an application of the operator to the first element of the list,
foldr can produce a terminating expression from an infinite list.
For a general Foldable structure this should be semantically identical
to,
foldr f z =foldrf z .toList
foldr' :: (a -> b -> b) -> b -> t a -> b #
Right-associative fold of a structure, but with strict application of the operator.
foldl' :: (b -> a -> b) -> b -> t a -> b #
Left-associative fold of a structure but with strict application of the operator.
This ensures that each step of the fold is forced to weak head normal
form before being applied, avoiding the collection of thunks that would
otherwise occur. This is often what you want to strictly reduce a finite
list to a single, monolithic result (e.g. length).
For a general Foldable structure this should be semantically identical
to,
foldl f z =foldl'f z .toList
List of elements of a structure, from left to right.
Test whether the structure is empty. The default implementation is optimized for structures that are similar to cons-lists, because there is no general way to do better.
Returns the size/length of a finite structure as an Int. The
default implementation is optimized for structures that are similar to
cons-lists, because there is no general way to do better.
elem :: Eq a => a -> t a -> Bool infix 4 #
Does the element occur in the structure?
The sum function computes the sum of the numbers of a structure.
product :: Num a => t a -> a #
The product function computes the product of the numbers of a
structure.
Instances
null :: Foldable t => forall a. t a -> Bool #
Test whether the structure is empty. The default implementation is optimized for structures that are similar to cons-lists, because there is no general way to do better.
length :: Foldable t => forall a. t a -> Int #
Returns the size/length of a finite structure as an Int. The
default implementation is optimized for structures that are similar to
cons-lists, because there is no general way to do better.
foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b #
Monadic fold over the elements of a structure, associating to the right, i.e. from right to left.
foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b #
Monadic fold over the elements of a structure, associating to the left, i.e. from left to right.
traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f () #
Map each element of a structure to an action, evaluate these
actions from left to right, and ignore the results. For a version
that doesn't ignore the results see traverse.
for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () #
asum :: (Foldable t, Alternative f) => t (f a) -> f a #
The sum of a collection of actions, generalizing concat.
concatMap :: Foldable t => (a -> [b]) -> t a -> [b] #
Map a function over all the elements of a container and concatenate the resulting lists.
all :: Foldable t => (a -> Bool) -> t a -> Bool #
Determines whether all elements of the structure satisfy the predicate.
any :: Foldable t => (a -> Bool) -> t a -> Bool #
Determines whether any element of the structure satisfies the predicate.
sequenceA_ :: (Foldable t, Applicative f) => t (f a) -> f () #
Evaluate each action in the structure from left to right, and
ignore the results. For a version that doesn't ignore the results
see sequenceA.
maximumByMay :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a #
maximumByDef :: Foldable t => a -> (a -> a -> Ordering) -> t a -> a #
minimumByMay :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a #
minimumByDef :: Foldable t => a -> (a -> a -> Ordering) -> t a -> a #
maximumMay :: (Foldable t, Ord a) => t a -> Maybe a #
maximumDef :: (Foldable t, Ord a) => a -> t a -> a #
minimumMay :: (Foldable t, Ord a) => t a -> Maybe a #
minimumDef :: (Foldable t, Ord a) => a -> t a -> a #
Traversable
class (Functor t, Foldable t) => Traversable t where #
Functors representing data structures that can be traversed from left to right.
A definition of traverse must satisfy the following laws:
- naturality
t .for every applicative transformationtraversef =traverse(t . f)t- identity
traverseIdentity = Identity- composition
traverse(Compose .fmapg . f) = Compose .fmap(traverseg) .traversef
A definition of sequenceA must satisfy the following laws:
- naturality
t .for every applicative transformationsequenceA=sequenceA.fmaptt- identity
sequenceA.fmapIdentity = Identity- composition
sequenceA.fmapCompose = Compose .fmapsequenceA.sequenceA
where an applicative transformation is a function
t :: (Applicative f, Applicative g) => f a -> g a
preserving the Applicative operations, i.e.
and the identity functor Identity and composition of functors Compose
are defined as
newtype Identity a = Identity a
instance Functor Identity where
fmap f (Identity x) = Identity (f x)
instance Applicative Identity where
pure x = Identity x
Identity f <*> Identity x = Identity (f x)
newtype Compose f g a = Compose (f (g a))
instance (Functor f, Functor g) => Functor (Compose f g) where
fmap f (Compose x) = Compose (fmap (fmap f) x)
instance (Applicative f, Applicative g) => Applicative (Compose f g) where
pure x = Compose (pure (pure x))
Compose f <*> Compose x = Compose ((<*>) <$> f <*> x)(The naturality law is implied by parametricity.)
Instances are similar to Functor, e.g. given a data type
data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
a suitable instance would be
instance Traversable Tree where traverse f Empty = pure Empty traverse f (Leaf x) = Leaf <$> f x traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r
This is suitable even for abstract types, as the laws for <*>
imply a form of associativity.
The superclass instances should satisfy the following:
- In the
Functorinstance,fmapshould be equivalent to traversal with the identity applicative functor (fmapDefault). - In the
Foldableinstance,foldMapshould be equivalent to traversal with a constant applicative functor (foldMapDefault).
Methods
traverse :: Applicative f => (a -> f b) -> t a -> f (t b) #
Map each element of a structure to an action, evaluate these actions
from left to right, and collect the results. For a version that ignores
the results see traverse_.
sequenceA :: Applicative f => t (f a) -> f (t a) #
Evaluate each action in the structure from left to right, and
and collect the results. For a version that ignores the results
see sequenceA_.
Instances
for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) #
mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c) #
mapAccumR :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c) #
Applicative
class Functor f => Applicative f where #
A functor with application, providing operations to
A minimal complete definition must include implementations of these functions satisfying the following laws:
- identity
pureid<*>v = v- composition
pure(.)<*>u<*>v<*>w = u<*>(v<*>w)- homomorphism
puref<*>purex =pure(f x)- interchange
u
<*>purey =pure($y)<*>u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor instance for f will satisfy
If f is also a Monad, it should satisfy
(which implies that pure and <*> satisfy the applicative functor laws).
Methods
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Instances
Lists, but with an Applicative functor based on zipping, so that
f<$>ZipListxs1<*>...<*>ZipListxsn =ZipList(zipWithn f xs1 ... xsn)
Constructors
| ZipList | |
Fields
| |
Instances
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 #
A variant of <*> with the arguments reversed.
liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #
Lift a ternary function to actions.
skip :: Applicative m => m () Source #
() lifted to an Applicative.
skip = pure ()(<>^) :: (Applicative f, Semigroup a) => f a -> f a -> f a infixr 6 Source #
<> lifted to Applicative
Alternative
class Applicative f => Alternative f where #
A monoid on applicative functors.
If defined, some and many should be the least solutions
of the equations:
Methods
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
Zero or more.
Instances
| Alternative [] | |
| Alternative Maybe | |
| Alternative IO | |
| Alternative U1 | |
| Alternative Option | |
| Alternative Seq | |
| Alternative DList | |
| Alternative f => Alternative (Rec1 f) | |
| MonadPlus m => Alternative (WrappedMonad m) | |
| Alternative (Proxy *) | |
| (Functor m, Monad m) => Alternative (MaybeT m) | |
| (Alternative f, Alternative g) => Alternative ((:*:) f g) | |
| (Alternative f, Applicative g) => Alternative ((:.:) f g) | |
| (ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b) | |
| Alternative f => Alternative (Alt * f) | |
| (Functor m, Monad m, Error e) => Alternative (ErrorT e m) | |
| (Functor m, Monad m, Monoid e) => Alternative (ExceptT e m) | |
| (Functor m, MonadPlus m) => Alternative (StateT s m) | |
| (Functor m, MonadPlus m) => Alternative (WriterT w m) | |
| Alternative f => Alternative (M1 i c f) | |
| (Alternative f, Alternative g) => Alternative (Product * f g) | |
| Alternative m => Alternative (ReaderT * r m) | |
| (Alternative f, Applicative g) => Alternative (Compose * * f g) | |
| (Functor m, MonadPlus m) => Alternative (RWST r w s m) | |
optional :: Alternative f => f a -> f (Maybe a) #
One or none.
some1 :: Alternative f => f a -> f (NonEmpty a) #
sequences some1 xx one or more times.
Monad
class Applicative m => Monad m where #
The Monad class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do expressions provide a convenient syntax for writing
monadic expressions.
Instances of Monad should satisfy the following laws:
Furthermore, the Monad and Applicative operations should relate as follows:
The above laws imply:
and that pure and (<*>) satisfy the applicative functor laws.
The instances of Monad for lists, Maybe and IO
defined in the Prelude satisfy these laws.
Minimal complete definition
Methods
(>>=) :: m a -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
Instances
| Monad [] | |
| Monad Maybe | |
| Monad IO | |
| Monad U1 | |
| Monad Par1 | |
| Monad Identity | |
| Monad Min | |
| Monad Max | |
| Monad First | |
| Monad Last | |
| Monad Option | |
| Monad NonEmpty | |
| Monad Complex | |
| Monad Dual | |
| Monad Sum | |
| Monad Product | |
| Monad First | |
| Monad Last | |
| Monad Seq | |
| Monad DList | |
| Monad ((->) r) | |
| Monad (Either e) | |
| Monad f => Monad (Rec1 f) | |
| Monoid a => Monad ((,) a) | |
| Monad m => Monad (WrappedMonad m) | |
| Monad (Proxy *) | |
| Monad (State s) | |
| Monad m => Monad (MaybeT m) | |
| (Monad f, Monad g) => Monad ((:*:) f g) | |
| Monad f => Monad (Alt * f) | |
| (Monad m, Error e) => Monad (ErrorT e m) | |
| Monad m => Monad (ExceptT e m) | |
| Monad m => Monad (StateT s m) | |
| Monad (Tagged k s) | |
| Monad m => Monad (WriterT w m) | |
| Monad f => Monad (M1 i c f) | |
| (Monad f, Monad g) => Monad (Product * f g) | |
| Monad m => Monad (ReaderT * r m) | |
| Monad m => Monad (RWST r w s m) | |
class Monad m => MonadFail m where #
When a value is bound in do-notation, the pattern on the left
hand side of <- might not match. In this case, this class
provides a function to recover.
A Monad without a MonadFail instance may only be used in conjunction
with pattern that always match, such as newtypes, tuples, data types with
only a single data constructor, and irrefutable patterns (~pat).
Instances of MonadFail should satisfy the following law: fail s should
be a left zero for >>=,
fail s >>= f = fail s
If your Monad is also MonadPlus, a popular definition is
fail _ = mzero
Since: 4.9.0.0
Minimal complete definition
Instances
| MonadFail [] | |
| MonadFail Maybe | |
| MonadFail IO | |
| Monad m => MonadFail (MaybeT m) | |
| (Monad m, Error e) => MonadFail (ErrorT e m) | |
| MonadFail m => MonadFail (ExceptT e m) | |
| MonadFail m => MonadFail (StateT s m) | |
| MonadFail m => MonadFail (WriterT w m) | |
| MonadFail m => MonadFail (ReaderT * r m) | |
| MonadFail m => MonadFail (RWST r w s m) | |
class Monad m => MonadFix m where #
Monads having fixed points with a 'knot-tying' semantics.
Instances of MonadFix should satisfy the following laws:
- purity
mfix(return. h) =return(fixh)- left shrinking (or tightening)
mfix(\x -> a >>= \y -> f x y) = a >>= \y ->mfix(\x -> f x y)- sliding
, for strictmfix(liftMh . f) =liftMh (mfix(f . h))h.- nesting
mfix(\x ->mfix(\y -> f x y)) =mfix(\x -> f x x)
This class is used in the translation of the recursive do notation
supported by GHC and Hugs.
Minimal complete definition
Methods
Instances
| MonadFix [] | |
| MonadFix Maybe | |
| MonadFix IO | |
| MonadFix Par1 | |
| MonadFix Identity | |
| MonadFix Min | |
| MonadFix Max | |
| MonadFix First | |
| MonadFix Last | |
| MonadFix Option | |
| MonadFix NonEmpty | |
| MonadFix Dual | |
| MonadFix Sum | |
| MonadFix Product | |
| MonadFix First | |
| MonadFix Last | |
| MonadFix ((->) r) | |
| MonadFix (Either e) | |
| MonadFix f => MonadFix (Rec1 f) | |
| MonadFix (ST s) | |
| MonadFix m => MonadFix (MaybeT m) | |
| (MonadFix f, MonadFix g) => MonadFix ((:*:) f g) | |
| MonadFix f => MonadFix (Alt * f) | |
| (MonadFix m, Error e) => MonadFix (ErrorT e m) | |
| MonadFix m => MonadFix (ExceptT e m) | |
| MonadFix m => MonadFix (StateT s m) | |
| MonadFix m => MonadFix (WriterT w m) | |
| MonadFix f => MonadFix (M1 i c f) | |
| (MonadFix f, MonadFix g) => MonadFix (Product * f g) | |
| MonadFix m => MonadFix (ReaderT * r m) | |
| MonadFix m => MonadFix (RWST r w s m) | |
(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 #
Same as >>=, but with the arguments interchanged.
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 #
Left-to-right Kleisli composition of monads.
class (Alternative m, Monad m) => MonadPlus m where #
Monads that also support choice and failure.
Methods
the identity of mplus. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
an associative operation
Instances
| MonadPlus [] | |
| MonadPlus Maybe | |
| MonadPlus IO | |
| MonadPlus U1 | |
| MonadPlus Option | |
| MonadPlus Seq | |
| MonadPlus DList | |
| MonadPlus f => MonadPlus (Rec1 f) | |
| MonadPlus (Proxy *) | |
| Monad m => MonadPlus (MaybeT m) | |
| (MonadPlus f, MonadPlus g) => MonadPlus ((:*:) f g) | |
| MonadPlus f => MonadPlus (Alt * f) | |
| (Monad m, Error e) => MonadPlus (ErrorT e m) | |
| (Monad m, Monoid e) => MonadPlus (ExceptT e m) | |
| MonadPlus m => MonadPlus (StateT s m) | |
| (Functor m, MonadPlus m) => MonadPlus (WriterT w m) | |
| MonadPlus f => MonadPlus (M1 i c f) | |
| (MonadPlus f, MonadPlus g) => MonadPlus (Product * f g) | |
| MonadPlus m => MonadPlus (ReaderT * r m) | |
| (Functor m, MonadPlus m) => MonadPlus (RWST r w s m) | |
join :: Monad m => m (m a) -> m a #
The join function is the conventional monad join operator. It
is used to remove one level of monadic structure, projecting its
bound argument into the outer level.
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging if the Boolean value debug
is True, and otherwise do nothing.
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when.
replicateM :: Applicative m => Int -> m a -> m [a] #
performs the action replicateM n actn times,
gathering the results.
replicateM_ :: Applicative m => Int -> m a -> m () #
Like replicateM, but discards the result.
allM :: Monad m => (a -> m Bool) -> [a] -> m Bool #
A version of all lifted to a monad. Retains the short-circuiting behaviour.
allM Just [True,False,undefined] == Just False allM Just [True,True ,undefined] == undefined \(f :: Int -> Maybe Bool) xs -> anyM f xs == orM (map f xs)
anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool #
A version of any lifted to a monad. Retains the short-circuiting behaviour.
anyM Just [False,True ,undefined] == Just True anyM Just [False,False,undefined] == undefined \(f :: Int -> Maybe Bool) xs -> anyM f xs == orM (map f xs)
andM :: Monad m => [m Bool] -> m Bool #
A version of and lifted to a monad. Retains the short-circuiting behaviour.
andM [Just True,Just False,undefined] == Just False andM [Just True,Just True ,undefined] == undefined \xs -> Just (and xs) == andM (map Just xs)
orM :: Monad m => [m Bool] -> m Bool #
A version of or lifted to a monad. Retains the short-circuiting behaviour.
orM [Just False,Just True ,undefined] == Just True orM [Just False,Just False,undefined] == undefined \xs -> Just (or xs) == orM (map Just xs)
concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b] #
A version of concatMap that works with a monadic predicate.
Bifunctor
Formally, the class Bifunctor represents a bifunctor
from Hask -> Hask.
Intuitively it is a bifunctor where both the first and second arguments are covariant.
You can define a Bifunctor by either defining bimap or by
defining both first and second.
If you supply bimap, you should ensure that:
bimapidid≡id
If you supply first and second, ensure:
firstid≡idsecondid≡id
If you supply both, you should also ensure:
bimapf g ≡firstf.secondg
These ensure by parametricity:
bimap(f.g) (h.i) ≡bimapf h.bimapg ifirst(f.g) ≡firstf.firstgsecond(f.g) ≡secondf.secondg
Since: 4.8.0.0
Bifoldable
class Bifoldable p where #
Bifoldable identifies foldable structures with two different varieties
of elements (as opposed to Foldable, which has one variety of element).
Common examples are Either and '(,)':
instance Bifoldable Either where bifoldMap f _ (Left a) = f a bifoldMap _ g (Right b) = g b instance Bifoldable (,) where bifoldr f g z (a, b) = f a (g b z)
A minimal Bifoldable definition consists of either bifoldMap or
bifoldr. When defining more than this minimal set, one should ensure
that the following identities hold:
bifold≡bifoldMapididbifoldMapf g ≡bifoldr(mappend. f) (mappend. g)memptybifoldrf g z t ≡appEndo(bifoldMap(Endo . f) (Endo . g) t) z
If the type is also a Bifunctor instance, it should satisfy:
'bifoldMap' f g ≡ 'bifold' . 'bimap' f g
which implies that
'bifoldMap' f g . 'bimap' h i ≡ 'bifoldMap' (f . h) (g . i)
Methods
bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> p a b -> m #
Combines the elements of a structure, given ways of mapping them to a common monoid.
bifoldMapf g ≡bifoldr(mappend. f) (mappend. g)mempty
bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c #
Instances
| Bifoldable Either | |
| Bifoldable (,) | |
| Bifoldable Arg | |
| Bifoldable (K1 i) | |
| Bifoldable ((,,) x) | |
| Bifoldable (Const *) | |
| Bifoldable (Tagged *) | |
| Bifoldable (Constant *) | |
| Bifoldable ((,,,) x y) | |
| Bifoldable ((,,,,) x y z) | |
| Bifoldable ((,,,,,) x y z w) | |
| Bifoldable ((,,,,,,) x y z w v) | |
bifoldl' :: Bifoldable t => (a -> b -> a) -> (a -> c -> a) -> a -> t b c -> a #
As bifoldl, but strict in the result of the reduction functions at each
step.
This ensures that each step of the bifold is forced to weak head normal form
before being applied, avoiding the collection of thunks that would otherwise
occur. This is often what you want to strictly reduce a finite structure to
a single, monolithic result (e.g., bilength).
bifoldr' :: Bifoldable t => (a -> c -> c) -> (b -> c -> c) -> c -> t a b -> c #
As bifoldr, but strict in the result of the reduction functions at each
step.
bitraverse_ :: (Bifoldable t, Applicative f) => (a -> f c) -> (b -> f d) -> t a b -> f () #
Map each element of a structure using one of two actions, evaluate these
actions from left to right, and ignore the results. For a version that
doesn't ignore the results, see bitraverse.
bisequenceA_ :: (Bifoldable t, Applicative f) => t (f a) (f b) -> f () #
As bisequenceA, but ignores the results of the actions.
bifor_ :: (Bifoldable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f () #
As bitraverse_, but with the structure as the primary argument. For a
version that doesn't ignore the results, see bifor.
>>>> bifor_ ('a', "bc") print (print . reverse)'a' "cb"
Bitraversable
class (Bifunctor t, Bifoldable t) => Bitraversable t where #
Bitraversable identifies bifunctorial data structures whose elements can
be traversed in order, performing Applicative or Monad actions at each
element, and collecting a result structure with the same shape.
As opposed to Traversable data structures, which have one variety of
element on which an action can be performed, Bitraversable data structures
have two such varieties of elements.
A definition of traverse must satisfy the following laws:
- naturality
for every applicative transformationbitraverse(t . f) (t . g) ≡ t .bitraversef gt- identity
bitraverseIdentityIdentity≡Identity- composition
Compose.fmap(bitraverseg1 g2) .bitraversef1 f2 ≡traverse(Compose.fmapg1 . f1) (Compose.fmapg2 . f2)
where an applicative transformation is a function
t :: (Applicativef,Applicativeg) => f a -> g a
preserving the Applicative operations:
t (purex) =purex t (f<*>x) = t f<*>t x
and the identity functor Identity and composition functors Compose are
defined as
newtype Identity a = Identity { runIdentity :: a }
instance Functor Identity where
fmap f (Identity x) = Identity (f x)
instance Applicative Identity where
pure = Identity
Identity f <*> Identity x = Identity (f x)
newtype Compose f g a = Compose (f (g a))
instance (Functor f, Functor g) => Functor (Compose f g) where
fmap f (Compose x) = Compose (fmap (fmap f) x)
instance (Applicative f, Applicative g) => Applicative (Compose f g) where
pure = Compose . pure . pure
Compose f <*> Compose x = Compose ((<*>) <$> f <*> x)Some simple examples are Either and '(,)':
instance Bitraversable Either where bitraverse f _ (Left x) = Left <$> f x bitraverse _ g (Right y) = Right <$> g y instance Bitraversable (,) where bitraverse f g (x, y) = (,) <$> f x <*> g y
Bitraversable relates to its superclasses in the following ways:
bimapf g ≡runIdentity.bitraverse(Identity. f) (Identity. g)bifoldMapf g =getConst.bitraverse(Const. f) (Const. g)
These are available as bimapDefault and bifoldMapDefault respectively.
Methods
bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> t a b -> f (t c d) #
Evaluates the relevant functions at each element in the structure, running the action, and builds a new structure with the same shape, using the elements produced from sequencing the actions.
bitraversef g ≡bisequenceA.bimapf g
For a version that ignores the results, see bitraverse_.
Instances
| Bitraversable Either | |
| Bitraversable (,) | |
| Bitraversable Arg | |
| Bitraversable (K1 i) | |
| Bitraversable ((,,) x) | |
| Bitraversable (Const *) | |
| Bitraversable (Tagged *) | |
| Bitraversable (Constant *) | |
| Bitraversable ((,,,) x y) | |
| Bitraversable ((,,,,) x y z) | |
| Bitraversable ((,,,,,) x y z w) | |
| Bitraversable ((,,,,,,) x y z w v) | |
bifor :: (Bitraversable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f (t c d) #
bifor is bitraverse with the structure as the first argument. For a
version that ignores the results, see bifor_.
bisequenceA :: (Bitraversable t, Applicative f) => t (f a) (f b) -> f (t a b) #
Sequences all the actions in a structure, building a new structure with the
same shape using the results of the actions. For a version that ignores the
results, see bisequenceA_.
bisequenceA≡bitraverseidid
Monad transformer
class MonadTrans t where #
The class of monad transformers. Instances should satisfy the
following laws, which state that lift is a monad transformation:
Minimal complete definition
Methods
lift :: Monad m => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.
Instances
| MonadTrans MaybeT | |
| MonadTrans (ErrorT e) | |
| MonadTrans (ExceptT e) | |
| MonadTrans (StateT s) | |
| MonadTrans (WriterT w) | |
| MonadTrans (ReaderT * r) | |
| MonadTrans (RWST r w s) | |
MaybeT
newtype MaybeT m a :: (* -> *) -> * -> * #
The parameterizable maybe monad, obtained by composing an arbitrary
monad with the Maybe monad.
Computations are actions that may produce a value or exit.
The return function yields a computation that produces that
value, while >>= sequences two subcomputations, exiting if either
computation does.
Instances
| MonadTrans MaybeT | |
| MonadRWS r w s m => MonadRWS r w s (MaybeT m) | |
| MonadError e m => MonadError e (MaybeT m) | |
| MonadReader r m => MonadReader r (MaybeT m) | |
| MonadState s m => MonadState s (MaybeT m) | |
| MonadWriter w m => MonadWriter w (MaybeT m) | |
| Monad m => Monad (MaybeT m) | |
| Functor m => Functor (MaybeT m) | |
| MonadFix m => MonadFix (MaybeT m) | |
| Monad m => MonadFail (MaybeT m) | |
| (Functor m, Monad m) => Applicative (MaybeT m) | |
| Foldable f => Foldable (MaybeT f) | |
| Traversable f => Traversable (MaybeT f) | |
| Eq1 m => Eq1 (MaybeT m) | |
| Ord1 m => Ord1 (MaybeT m) | |
| Read1 m => Read1 (MaybeT m) | |
| Show1 m => Show1 (MaybeT m) | |
| MonadZip m => MonadZip (MaybeT m) | |
| MonadIO m => MonadIO (MaybeT m) | |
| (Functor m, Monad m) => Alternative (MaybeT m) | |
| Monad m => MonadPlus (MaybeT m) | |
| (Eq1 m, Eq a) => Eq (MaybeT m a) | |
| (Ord1 m, Ord a) => Ord (MaybeT m a) | |
| (Read1 m, Read a) => Read (MaybeT m a) | |
| (Show1 m, Show a) => Show (MaybeT m a) | |
MonadError and ExceptT
class Monad m => MonadError e m | m -> e where #
The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled.
Is parameterized over the type of error information and
the monad type constructor.
It is common to use as the monad type constructor
for an error monad in which error descriptions take the form of strings.
In that case and many other common cases the resulting monad is already defined
as an instance of the Either StringMonadError class.
You can also define your own error type and/or use a monad type constructor
other than or Either String.
In these cases you will have to explicitly define instances of the Either IOErrorError
and/or MonadError classes.
Minimal complete definition
Methods
throwError :: e -> m a #
Is used within a monadic computation to begin exception processing.
catchError :: m a -> (e -> m a) -> m a #
A handler function to handle previous errors and return to normal execution. A common idiom is:
do { action1; action2; action3 } `catchError` handlerwhere the action functions can call throwError.
Note that handler and the do-block must have the same return type.
Instances
| MonadError IOException IO | |
| MonadError e m => MonadError e (MaybeT m) | |
| MonadError e m => MonadError e (ListT m) | |
| MonadError e (Either e) | |
| (Monoid w, MonadError e m) => MonadError e (WriterT w m) | |
| (Monoid w, MonadError e m) => MonadError e (WriterT w m) | |
| MonadError e m => MonadError e (StateT s m) | |
| MonadError e m => MonadError e (StateT s m) | |
| MonadError e m => MonadError e (IdentityT * m) | |
| Monad m => MonadError e (ExceptT e m) | |
| (Monad m, Error e) => MonadError e (ErrorT e m) | |
| MonadError e m => MonadError e (ReaderT * r m) | |
| (Monoid w, MonadError e m) => MonadError e (RWST r w s m) | |
| (Monoid w, MonadError e m) => MonadError e (RWST r w s m) | |
runExcept :: Except e a -> Either e a #
Extractor for computations in the exception monad.
(The inverse of except).
withExcept :: (e -> e') -> Except e a -> Except e' a #
Transform any exceptions thrown by the computation using the given
function (a specialization of withExceptT).
newtype ExceptT e m a :: * -> (* -> *) -> * -> * #
A monad transformer that adds exceptions to other monads.
ExceptT constructs a monad parameterized over two things:
- e - The exception type.
- m - The inner monad.
The return function yields a computation that produces the given
value, while >>= sequences two subcomputations, exiting on the
first exception.
Instances
runExceptT :: ExceptT e m a -> m (Either e a) #
The inverse of ExceptT.
mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b #
Map the unwrapped computation using the given function.
runExceptT(mapExceptTf m) = f (runExceptTm)
withExceptT :: Functor m => (e -> e') -> ExceptT e m a -> ExceptT e' m a #
Transform any exceptions thrown by the computation using the given function.
MonadReader and ReaderT
class Monad m => MonadReader r m | m -> r where #
See examples in Control.Monad.Reader.
Note, the partially applied function type (->) r is a simple reader monad.
See the instance declaration below.
Methods
Retrieves the monad environment.
local :: (r -> r) -> m a -> m a #
Executes a computation in a modified environment.
Retrieves a function of the current environment.
Instances
| MonadReader r m => MonadReader r (MaybeT m) | |
| MonadReader r m => MonadReader r (ListT m) | |
| MonadReader r ((->) r) | |
| (Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | |
| (Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | |
| MonadReader r m => MonadReader r (StateT s m) | |
| MonadReader r m => MonadReader r (StateT s m) | |
| MonadReader r m => MonadReader r (IdentityT * m) | |
| MonadReader r m => MonadReader r (ExceptT e m) | |
| (Error e, MonadReader r m) => MonadReader r (ErrorT e m) | |
| Monad m => MonadReader r (ReaderT * r m) | |
| MonadReader r' m => MonadReader r' (ContT * r m) | |
| (Monad m, Monoid w) => MonadReader r (RWST r w s m) | |
| (Monad m, Monoid w) => MonadReader r (RWST r w s m) | |
Arguments
| :: MonadReader r m | |
| => (r -> a) | The selector function to apply to the environment. |
| -> m a |
Retrieves a function of the current environment.
type Reader r = ReaderT * r Identity #
The parameterizable reader monad.
Computations are functions of a shared environment.
The return function ignores the environment, while >>= passes
the inherited environment to both subcomputations.
Arguments
| :: Reader r a | A |
| -> r | An initial environment. |
| -> a |
Runs a Reader and extracts the final value from it.
(The inverse of reader.)
Arguments
| :: (r' -> r) | The function to modify the environment. |
| -> Reader r a | Computation to run in the modified environment. |
| -> Reader r' a |
Execute a computation in a modified environment
(a specialization of withReaderT).
runReader(withReaderf m) =runReaderm . f
newtype ReaderT k r m a :: forall k. * -> (k -> *) -> k -> * #
The reader monad transformer, which adds a read-only environment to the given monad.
The return function ignores the environment, while >>= passes
the inherited environment to both subcomputations.
Constructors
| ReaderT | |
Fields
| |
Instances
| MonadError e m => MonadError e (ReaderT * r m) | |
| Monad m => MonadReader r (ReaderT * r m) | |
| MonadState s m => MonadState s (ReaderT * r m) | |
| MonadWriter w m => MonadWriter w (ReaderT * r m) | |
| MonadTrans (ReaderT * r) | |
| Monad m => Monad (ReaderT * r m) | |
| Functor m => Functor (ReaderT * r m) | |
| MonadFix m => MonadFix (ReaderT * r m) | |
| MonadFail m => MonadFail (ReaderT * r m) | |
| Applicative m => Applicative (ReaderT * r m) | |
| MonadZip m => MonadZip (ReaderT * r m) | |
| MonadIO m => MonadIO (ReaderT * r m) | |
| Alternative m => Alternative (ReaderT * r m) | |
| MonadPlus m => MonadPlus (ReaderT * r m) | |
mapReaderT :: (m a -> n b) -> ReaderT k1 r m a -> ReaderT k r n b #
Transform the computation inside a ReaderT.
runReaderT(mapReaderTf m) = f .runReaderTm
Arguments
| :: (r' -> r) | The function to modify the environment. |
| -> ReaderT k r m a | Computation to run in the modified environment. |
| -> ReaderT k r' m a |
Execute a computation in a modified environment
(a more general version of local).
runReaderT(withReaderTf m) =runReaderTm . f
MonadWriter and WriterT
class (Monoid w, Monad m) => MonadWriter w m | m -> w where #
Methods
embeds a simple writer action.writer (a,w)
is an action that produces the output tell ww.
is an action that executes the action listen mm and adds
its output to the value of the computation.
pass :: m (a, w -> w) -> m a #
is an action that executes the action pass mm, which
returns a value and a function, and returns the value, applying
the function to the output.
Instances
| MonadWriter w m => MonadWriter w (MaybeT m) | |
| (Monoid w, Monad m) => MonadWriter w (WriterT w m) | |
| (Monoid w, Monad m) => MonadWriter w (WriterT w m) | |
| MonadWriter w m => MonadWriter w (StateT s m) | |
| MonadWriter w m => MonadWriter w (StateT s m) | |
| MonadWriter w m => MonadWriter w (IdentityT * m) | |
| MonadWriter w m => MonadWriter w (ExceptT e m) | |
| (Error e, MonadWriter w m) => MonadWriter w (ErrorT e m) | |
| MonadWriter w m => MonadWriter w (ReaderT * r m) | |
| (Monoid w, Monad m) => MonadWriter w (RWST r w s m) | |
| (Monoid w, Monad m) => MonadWriter w (RWST r w s m) | |
runWriter :: Monoid w => Writer w a -> (a, w) #
Unwrap a writer computation as a (result, output) pair.
(The inverse of writer.)
execWriter :: Monoid w => Writer w a -> w #
Extract the output from a writer computation.
execWriterm =snd(runWriterm)
data WriterT w m a :: * -> (* -> *) -> * -> * #
A writer monad parameterized by:
w- the output to accumulate.m- The inner monad.
The return function produces the output mempty, while >>=
combines the outputs of the subcomputations using mappend.
Instances
| MonadTrans (WriterT w) | |
| Monad m => Monad (WriterT w m) | |
| Functor m => Functor (WriterT w m) | |
| MonadFix m => MonadFix (WriterT w m) | |
| MonadFail m => MonadFail (WriterT w m) | |
| (Functor m, Monad m) => Applicative (WriterT w m) | |
| MonadIO m => MonadIO (WriterT w m) | |
| (Functor m, MonadPlus m) => Alternative (WriterT w m) | |
| (Functor m, MonadPlus m) => MonadPlus (WriterT w m) | |
writerT :: (Functor m, Monoid w) => m (a, w) -> WriterT w m a #
The WriterT constructor is deliberately not exported in the CPS module to avoid exposing the hidden state w. writerT provides a safe way to construct a WriterT with the same api as the original WriterT.
runWriterT :: Monoid w => WriterT w m a -> m (a, w) #
Unwrap a writer computation.
execWriterT :: (Monad m, Monoid w) => WriterT w m a -> m w #
Extract the output from a writer computation.
execWriterTm =liftMsnd(runWriterTm)
mapWriterT :: (Monad n, Monoid w, Monoid w') => (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b #
Map both the return value and output of a computation using the given function.
runWriterT(mapWriterTf m) = f (runWriterTm)
MonadState and StateT
class Monad m => MonadState s m | m -> s where #
Minimal definition is either both of get and put or just state
Methods
Return the state from the internals of the monad.
Replace the state inside the monad.
state :: (s -> (a, s)) -> m a #
Embed a simple state action into the monad.
Instances
| MonadState s m => MonadState s (MaybeT m) | |
| MonadState s m => MonadState s (ListT m) | |
| (Monoid w, MonadState s m) => MonadState s (WriterT w m) | |
| (Monoid w, MonadState s m) => MonadState s (WriterT w m) | |
| Monad m => MonadState s (StateT s m) | |
| Monad m => MonadState s (StateT s m) | |
| MonadState s m => MonadState s (IdentityT * m) | |
| MonadState s m => MonadState s (ExceptT e m) | |
| (Error e, MonadState s m) => MonadState s (ErrorT e m) | |
| MonadState s m => MonadState s (ReaderT * r m) | |
| MonadState s m => MonadState s (ContT * r m) | |
| (Monad m, Monoid w) => MonadState s (RWST r w s m) | |
| (Monad m, Monoid w) => MonadState s (RWST r w s m) | |
type State s = StateT s Identity #
A state monad parameterized by the type s of the state to carry.
The return function leaves the state unchanged, while >>= uses
the final state of the first computation as the initial state of
the second.
gets :: MonadState s m => (s -> a) -> m a #
Gets specific component of the state, using a projection function supplied.
modify :: MonadState s m => (s -> s) -> m () #
Monadic state transformer.
Maps an old state to a new state inside a state monad. The old state is thrown away.
Main> :t modify ((+1) :: Int -> Int)
modify (...) :: (MonadState Int a) => a ()This says that modify (+1) acts over any
Monad that is a member of the MonadState class,
with an Int state.
modify' :: MonadState s m => (s -> s) -> m () #
A variant of modify in which the computation is strict in the
new state.
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial state |
| -> (a, s) | return value and final state |
Unwrap a state monad computation as a function.
(The inverse of state.)
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial value |
| -> a | return value of the state computation |
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial value |
| -> s | final state |
newtype StateT s m a :: * -> (* -> *) -> * -> * #
A state transformer monad parameterized by:
s- The state.m- The inner monad.
The return function leaves the state unchanged, while >>= uses
the final state of the first computation as the initial state of
the second.
Instances
| MonadError e m => MonadError e (StateT s m) | |
| MonadReader r m => MonadReader r (StateT s m) | |
| Monad m => MonadState s (StateT s m) | |
| MonadWriter w m => MonadWriter w (StateT s m) | |
| MonadTrans (StateT s) | |
| Monad m => Monad (StateT s m) | |
| Functor m => Functor (StateT s m) | |
| MonadFix m => MonadFix (StateT s m) | |
| MonadFail m => MonadFail (StateT s m) | |
| (Functor m, Monad m) => Applicative (StateT s m) | |
| MonadIO m => MonadIO (StateT s m) | |
| (Functor m, MonadPlus m) => Alternative (StateT s m) | |
| MonadPlus m => MonadPlus (StateT s m) | |
evalStateT :: Monad m => StateT s m a -> s -> m a #
Evaluate a state computation with the given initial state and return the final value, discarding the final state.
evalStateTm s =liftMfst(runStateTm s)
execStateT :: Monad m => StateT s m a -> s -> m s #
Evaluate a state computation with the given initial state and return the final state, discarding the final value.
execStateTm s =liftMsnd(runStateTm s)
withStateT :: (s -> s) -> StateT s m a -> StateT s m a #
executes action withStateT f mm on a state modified by
applying f.
withStateTf m =modifyf >> m
MonadRWS and RWST
class (Monoid w, MonadReader r m, MonadWriter w m, MonadState s m) => MonadRWS r w s m | m -> r, m -> w, m -> s #
Instances
| MonadRWS r w s m => MonadRWS r w s (MaybeT m) | |
| MonadRWS r w s m => MonadRWS r w s (IdentityT * m) | |
| MonadRWS r w s m => MonadRWS r w s (ExceptT e m) | |
| (Error e, MonadRWS r w s m) => MonadRWS r w s (ErrorT e m) | |
| (Monoid w, Monad m) => MonadRWS r w s (RWST r w s m) | |
| (Monoid w, Monad m) => MonadRWS r w s (RWST r w s m) | |
type RWS r w s = RWST r w s Identity #
A monad containing an environment of type r, output of type w
and an updatable state of type s.
rws :: Monoid w => (r -> s -> (a, s, w)) -> RWS r w s a #
Construct an RWS computation from a function.
(The inverse of runRWS.)
runRWS :: Monoid w => RWS r w s a -> r -> s -> (a, s, w) #
Unwrap an RWS computation as a function.
(The inverse of rws.)
Arguments
| :: Monoid w | |
| => RWS r w s a | RWS computation to execute |
| -> r | initial environment |
| -> s | initial value |
| -> (a, w) | final value and output |
Evaluate a computation with the given initial state and environment, returning the final value and output, discarding the final state.
Arguments
| :: Monoid w | |
| => RWS r w s a | RWS computation to execute |
| -> r | initial environment |
| -> s | initial value |
| -> (s, w) | final state and output |
Evaluate a computation with the given initial state and environment, returning the final state and output, discarding the final value.
data RWST r w s m a :: * -> * -> * -> (* -> *) -> * -> * #
A monad transformer adding reading an environment of type r,
collecting an output of type w and updating a state of type s
to an inner monad m.
Instances
| MonadTrans (RWST r w s) | |
| Monad m => Monad (RWST r w s m) | |
| Functor m => Functor (RWST r w s m) | |
| MonadFix m => MonadFix (RWST r w s m) | |
| MonadFail m => MonadFail (RWST r w s m) | |
| (Functor m, Monad m) => Applicative (RWST r w s m) | |
| MonadIO m => MonadIO (RWST r w s m) | |
| (Functor m, MonadPlus m) => Alternative (RWST r w s m) | |
| (Functor m, MonadPlus m) => MonadPlus (RWST r w s m) | |
rwsT :: (Functor m, Monoid w) => (r -> s -> m (a, s, w)) -> RWST r w s m a #
The RWST constructor is deliberately not exported in the CPS module to avoid exposing the hidden state w. rwsT provides a safe way to construct a RWST with the same api as the original RWST.
runRWST :: Monoid w => RWST r w s m a -> r -> s -> m (a, s, w) #
Unwrap an RWST computation as a function.
Arguments
| :: (Monad m, Monoid w) | |
| => RWST r w s m a | computation to execute |
| -> r | initial environment |
| -> s | initial value |
| -> m (a, w) | computation yielding final value and output |
Evaluate a computation with the given initial state and environment, returning the final value and output, discarding the final state.
Arguments
| :: (Monad m, Monoid w) | |
| => RWST r w s m a | computation to execute |
| -> r | initial environment |
| -> s | initial value |
| -> m (s, w) | computation yielding final state and output |
Evaluate a computation with the given initial state and environment, returning the final state and output, discarding the final value.
mapRWST :: (Monad n, Monoid w, Monoid w') => (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b #
Generic type classes
Representable types of kind *. This class is derivable in GHC with the DeriveGeneric flag on.
Instances
Representable types of kind * -> *. This class is derivable in GHC with the DeriveGeneric flag on.
Instances
| Generic1 [] | |
| Generic1 Maybe | |
| Generic1 V1 | |
| Generic1 U1 | |
| Generic1 Par1 | |
| Generic1 Identity | |
| Generic1 Min | |
| Generic1 Max | |
| Generic1 First | |
| Generic1 Last | |
| Generic1 WrappedMonoid | |
| Generic1 Option | |
| Generic1 NonEmpty | |
| Generic1 Complex | |
| Generic1 ZipList | |
| Generic1 Dual | |
| Generic1 Sum | |
| Generic1 Product | |
| Generic1 First | |
| Generic1 Last | |
| Generic1 (Either a) | |
| Generic1 (Rec1 f) | |
| Generic1 (URec Char) | |
| Generic1 (URec Double) | |
| Generic1 (URec Float) | |
| Generic1 (URec Int) | |
| Generic1 (URec Word) | |
| Generic1 (URec (Ptr ())) | |
| Generic1 ((,) a) | |
| Generic1 (Arg a) | |
| Generic1 (WrappedMonad m) | |
| Generic1 (Proxy *) | |
| Generic1 (K1 i c) | |
| Generic1 ((:+:) f g) | |
| Generic1 ((:*:) f g) | |
| Functor f => Generic1 ((:.:) f g) | |
| Generic1 ((,,) a b) | |
| Generic1 (WrappedArrow a b) | |
| Generic1 (Const * a) | |
| Generic1 (Alt * f) | |
| Generic1 (Tagged k s) | |
| Generic1 (M1 i c f) | |
| Generic1 ((,,,) a b c) | |
| Generic1 (Sum * f g) | |
| Generic1 (Product * f g) | |
| Generic1 ((,,,,) a b c d) | |
| Functor f => Generic1 (Compose * * f g) | |
| Generic1 ((,,,,,) a b c d e) | |
| Generic1 ((,,,,,,) a b c d e f) | |
The class Typeable allows a concrete representation of a type to
be calculated.
Minimal complete definition
A class of types that can be fully evaluated.
Since: 1.1.0.0
Instances
| NFData Bool | |
| NFData Char | |
| NFData Double | |
| NFData Float | |
| NFData Int | |
| NFData Int8 | |
| NFData Int16 | |
| NFData Int32 | |
| NFData Int64 | |
| NFData Integer | |
| NFData Word | |
| NFData Word8 | |
| NFData Word16 | |
| NFData Word32 | |
| NFData Word64 | |
| NFData CallStack | Since: 1.4.2.0 |
| NFData TypeRep | NOTE: Only defined for Since: 1.4.0.0 |
| NFData () | |
| NFData TyCon | NOTE: Only defined for Since: 1.4.0.0 |
| NFData Natural | Since: 1.4.0.0 |
| NFData Void | Since: 1.4.0.0 |
| NFData Version | Since: 1.3.0.0 |
| NFData Unique | Since: 1.4.0.0 |
| NFData ThreadId | Since: 1.4.0.0 |
| NFData ExitCode | Since: 1.4.2.0 |
| NFData CChar | Since: 1.4.0.0 |
| NFData CSChar | Since: 1.4.0.0 |
| NFData CUChar | Since: 1.4.0.0 |
| NFData CShort | Since: 1.4.0.0 |
| NFData CUShort | Since: 1.4.0.0 |
| NFData CInt | Since: 1.4.0.0 |
| NFData CUInt | Since: 1.4.0.0 |
| NFData CLong | Since: 1.4.0.0 |
| NFData CULong | Since: 1.4.0.0 |
| NFData CLLong | Since: 1.4.0.0 |
| NFData CULLong | Since: 1.4.0.0 |
| NFData CFloat | Since: 1.4.0.0 |
| NFData CDouble | Since: 1.4.0.0 |
| NFData CPtrdiff | Since: 1.4.0.0 |
| NFData CSize | Since: 1.4.0.0 |
| NFData CWchar | Since: 1.4.0.0 |
| NFData CSigAtomic | Since: 1.4.0.0 |
| NFData CClock | Since: 1.4.0.0 |
| NFData CTime | Since: 1.4.0.0 |
| NFData CUSeconds | Since: 1.4.0.0 |
| NFData CSUSeconds | Since: 1.4.0.0 |
| NFData CFile | Since: 1.4.0.0 |
| NFData CFpos | Since: 1.4.0.0 |
| NFData CJmpBuf | Since: 1.4.0.0 |
| NFData CIntPtr | Since: 1.4.0.0 |
| NFData CUIntPtr | Since: 1.4.0.0 |
| NFData CIntMax | Since: 1.4.0.0 |
| NFData CUIntMax | Since: 1.4.0.0 |
| NFData All | Since: 1.4.0.0 |
| NFData Any | Since: 1.4.0.0 |
| NFData Fingerprint | Since: 1.4.0.0 |
| NFData SrcLoc | Since: 1.4.2.0 |
| NFData ByteString | |
| NFData ByteString | |
| NFData IntSet | |
| NFData a => NFData [a] | |
| NFData a => NFData (Maybe a) | |
| NFData a => NFData (Ratio a) | |
| NFData (Ptr a) | Since: 1.4.2.0 |
| NFData (FunPtr a) | Since: 1.4.2.0 |
| NFData a => NFData (Identity a) | Since: 1.4.0.0 |
| NFData a => NFData (Min a) | Since: 1.4.2.0 |
| NFData a => NFData (Max a) | Since: 1.4.2.0 |
| NFData a => NFData (First a) | Since: 1.4.2.0 |
| NFData a => NFData (Last a) | Since: 1.4.2.0 |
| NFData m => NFData (WrappedMonoid m) | Since: 1.4.2.0 |
| NFData a => NFData (Option a) | Since: 1.4.2.0 |
| NFData a => NFData (NonEmpty a) | Since: 1.4.2.0 |
| NFData (Fixed a) | Since: 1.3.0.0 |
| NFData a => NFData (Complex a) | |
| NFData (StableName a) | Since: 1.4.0.0 |
| NFData a => NFData (ZipList a) | Since: 1.4.0.0 |
| NFData a => NFData (Dual a) | Since: 1.4.0.0 |
| NFData a => NFData (Sum a) | Since: 1.4.0.0 |
| NFData a => NFData (Product a) | Since: 1.4.0.0 |
| NFData a => NFData (First a) | Since: 1.4.0.0 |
| NFData a => NFData (Last a) | Since: 1.4.0.0 |
| NFData (IORef a) | NOTE: Only strict in the reference and not the referenced value. Since: 1.4.2.0 |
| NFData a => NFData (Down a) | Since: 1.4.0.0 |
| NFData (MVar a) | NOTE: Only strict in the reference and not the referenced value. Since: 1.4.2.0 |
| NFData a => NFData (Digit a) | |
| NFData a => NFData (Node a) | |
| NFData a => NFData (Elem a) | |
| NFData a => NFData (FingerTree a) | |
| NFData a => NFData (IntMap a) | |
| NFData a => NFData (Seq a) | |
| NFData a => NFData (Set a) | |
| NFData a => NFData (DList a) | |
| NFData a => NFData (Array a) | |
| NFData a => NFData (HashSet a) | |
| NFData (a -> b) | This instance is for convenience and consistency with Since: 1.3.0.0 |
| (NFData a, NFData b) => NFData (Either a b) | |
| (NFData a, NFData b) => NFData (a, b) | |
| (NFData a, NFData b) => NFData (Array a b) | |
| (NFData a, NFData b) => NFData (Arg a b) | Since: 1.4.2.0 |
| NFData (Proxy k a) | Since: 1.4.0.0 |
| NFData (STRef s a) | NOTE: Only strict in the reference and not the referenced value. Since: 1.4.2.0 |
| (NFData k, NFData a) => NFData (Map k a) | |
| (NFData k, NFData v) => NFData (Leaf k v) | |
| (NFData k, NFData v) => NFData (HashMap k v) | |
| (NFData a, NFData b, NFData c) => NFData (a, b, c) | |
| NFData a => NFData (Const k a b) | Since: 1.4.0.0 |
| NFData b => NFData (Tagged k s b) | |
| (NFData a, NFData b, NFData c, NFData d) => NFData (a, b, c, d) | |
| (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5) => NFData (a1, a2, a3, a4, a5) | |
| (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6) => NFData (a1, a2, a3, a4, a5, a6) | |
| (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7) => NFData (a1, a2, a3, a4, a5, a6, a7) | |
| (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8) => NFData (a1, a2, a3, a4, a5, a6, a7, a8) | |
| (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8, NFData a9) => NFData (a1, a2, a3, a4, a5, a6, a7, a8, a9) | |
The Binary class provides put and get, methods to encode and
decode a Haskell value to a lazy ByteString. It mirrors the Read and
Show classes for textual representation of Haskell types, and is
suitable for serialising Haskell values to disk, over the network.
For decoding and generating simple external binary formats (e.g. C
structures), Binary may be used, but in general is not suitable
for complex protocols. Instead use the Put and Get primitives
directly.
Instances of Binary should satisfy the following property:
decode . encode == id
That is, the get and put methods should be the inverse of each
other. A range of instances are provided for basic Haskell types.
Instances
Type level
data Constraint :: * #
The kind of constraints, like Show a
data Proxy k t :: forall k. k -> * #
A concrete, poly-kinded proxy type
Constructors
| Proxy |
Instances
| Monad (Proxy *) | |
| Functor (Proxy *) | |
| Applicative (Proxy *) | |
| Foldable (Proxy *) | |
| Traversable (Proxy *) | |
| Generic1 (Proxy *) | |
| Eq1 (Proxy *) | Since: 4.9.0.0 |
| Ord1 (Proxy *) | Since: 4.9.0.0 |
| Read1 (Proxy *) | Since: 4.9.0.0 |
| Show1 (Proxy *) | Since: 4.9.0.0 |
| Alternative (Proxy *) | |
| MonadPlus (Proxy *) | |
| Hashable1 (Proxy *) | |
| Bounded (Proxy k s) | |
| Enum (Proxy k s) | |
| Eq (Proxy k s) | |
| Ord (Proxy k s) | |
| Read (Proxy k s) | |
| Show (Proxy k s) | |
| Ix (Proxy k s) | |
| Generic (Proxy k t) | |
| Semigroup (Proxy k s) | |
| Monoid (Proxy k s) | |
| NFData (Proxy k a) | Since: 1.4.0.0 |
| Hashable (Proxy * a) | |
| type Rep1 (Proxy *) | |
| type Rep (Proxy k t) | |
newtype Tagged k s b :: forall k. k -> * -> * #
A value is a value Tagged s bb with an attached phantom type s.
This can be used in place of the more traditional but less safe idiom of
passing in an undefined value with the type, because unlike an (s -> b),
a can't try to use the argument Tagged s bs as a real value.
Moreover, you don't have to rely on the compiler to inline away the extra argument, because the newtype is "free"
Tagged has kind k -> * -> * if the compiler supports PolyKinds, therefore
there is an extra k showing in the instance haddocks that may cause confusion.
Instances
IO
A value of type is a computation which, when performed,
does some I/O before returning a value of type IO aa.
There is really only one way to "perform" an I/O action: bind it to
Main.main in your program. When your program is run, the I/O will
be performed. It isn't possible to perform I/O from an arbitrary
function, unless that function is itself in the IO monad and called
at some point, directly or indirectly, from Main.main.
IO is a monad, so IO actions can be combined using either the do-notation
or the >> and >>= operations from the Monad class.
class Monad m => MonadIO m where #
Monads in which IO computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
Minimal complete definition
Console
getChar :: MonadIO m => m Char Source #
Read a character from the standard input device.
Note: This function is lifted to the MonadIO class.
getContents :: MonadIO m => m Text Source #
The getContents operation returns all user input as a strict Text.
Note: This function is lifted to the MonadIO class.
print :: (MonadIO m, Show a) => a -> m () Source #
The print function outputs a value of any printable type to the
standard output device.
Printable types are those that are instances of class Show; print
converts values to strings for output using the show operation and
adds a newline.
For example, a program to print the first 20 integers and their powers of 2 could be written as:
main = print ([(n, 2^n) | n <- [0..19]])
Note: This function is lifted to the MonadIO class.
putChar :: MonadIO m => Char -> m () Source #
Write a character to the standard output device.
Note: This function is lifted to the MonadIO class.
File
File and directory names are values of type String, whose precise
meaning is operating system dependent. Files can be opened, yielding a
handle which can then be used to operate on the contents of that file.
readFile :: MonadIO m => FilePath -> m ByteString Source #
Read an entire file strictly into a ByteString.
Note: This function is lifted to the MonadIO class.
writeFile :: MonadIO m => FilePath -> ByteString -> m () Source #
Write a ByteString to a file.
Note: This function is lifted to the MonadIO class.
appendFile :: MonadIO m => FilePath -> ByteString -> m () Source #
Append a ByteString to a file.
Note: This function is lifted to the MonadIO class.
Error and Debugging
panic :: HasCallStack => Text -> a Source #
Throw an unhandled error to terminate the program in case
of a logic error at runtime. Use this function instead of error.
A stack trace will be provided.
In general, prefer total functions. You can use Maybe, Either,
ExceptT or MonadError for error handling.
undefined :: HasCallStack => a Source #
Warning: undefined remains in code
Throw an undefined error. Use only for debugging.
trace :: Text -> a -> a Source #
Warning: trace remains in code
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.
traceM :: Applicative m => Text -> m () Source #
Warning: traceM remains in code
Like trace but returning unit in an arbitrary Applicative context. Allows
for convenient use in do-notation.
Note that the application of traceM is not an action in the Applicative
context, as traceIO is in the MonadIO type. While the fresh bindings in the
following example will force the traceM expressions to be reduced every time
the do-block is executed, traceM "not crashed" would only be reduced once,
and the message would only be printed once. If your monad is in MonadIO,
traceIO may be a better option.
... = do x <- ... traceM $ "x: " ++ show x y <- ... traceM $ "y: " ++ show y
traceShow :: Show a => a -> b -> b Source #
Warning: traceShow remains in code
Like trace, but uses show on the argument to convert it to a String.
This makes it convenient for printing the values of interesting variables or
expressions inside a function. For example here we print the value of the
variables x and z:
f x y =
traceShow (x, z) $ result
where
z = ...
...traceShowM :: (Show a, Applicative m) => a -> m () Source #
Warning: traceShowM remains in code
Like traceM, but uses show on the argument to convert it to a String.
... = do x <- ... traceShowM $ x y <- ... traceShowM $ x + y