foundation-0.0.13: Alternative prelude with batteries and no dependencies

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Foundation

Contents

Description

I tried to picture clusters of information As they moved through the computer What do they look like?

Alternative Prelude

Synopsis

Standard

Operators

($) :: (a -> b) -> a -> b infixr 0

Application operator. This operator is redundant, since ordinary application (f x) means the same as (f $ x). However, $ 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 map ($ 0) xs, or 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.

(&&) :: Bool -> Bool -> Bool infixr 3

Boolean "and"

(||) :: Bool -> Bool -> Bool infixr 2

Boolean "or"

(.) :: Category k cat => forall b c a. cat b c -> cat a b -> cat a c

morphism composition

Functions

not :: Bool -> Bool

Boolean "not"

otherwise :: Bool

otherwise is defined as the value True. It helps to make guards more readable. eg.

 f x | x < 0     = ...
     | otherwise = ...

data Tuple2 a b

Strict tuple (a,b)

Constructors

Tuple2 !a !b 

Instances

Bifunctor Tuple2 
Nthable 1 (Tuple2 a b) 
Nthable 2 (Tuple2 a b) 
(Eq a, Eq b) => Eq (Tuple2 a b) 
(Data a, Data b) => Data (Tuple2 a b) 
(Ord a, Ord b) => Ord (Tuple2 a b) 
(Show a, Show b) => Show (Tuple2 a b) 
Generic (Tuple2 a b) 
(NormalForm a, NormalForm b) => NormalForm (Tuple2 a b) 
Sndable (Tuple2 a b) 
Fstable (Tuple2 a b) 
(Hashable a, Hashable b) => Hashable (Tuple2 a b) 
type NthTy 1 (Tuple2 a b) = a 
type NthTy 2 (Tuple2 a b) = b 
type Rep (Tuple2 a b) 
type ProductSecond (Tuple2 a b) = b 
type ProductFirst (Tuple2 a b) = a 

data Tuple3 a b c

Strict tuple (a,b,c)

Constructors

Tuple3 !a !b !c 

Instances

Nthable 1 (Tuple3 a b c) 
Nthable 2 (Tuple3 a b c) 
Nthable 3 (Tuple3 a b c) 
(Eq a, Eq b, Eq c) => Eq (Tuple3 a b c) 
(Data a, Data b, Data c) => Data (Tuple3 a b c) 
(Ord a, Ord b, Ord c) => Ord (Tuple3 a b c) 
(Show a, Show b, Show c) => Show (Tuple3 a b c) 
Generic (Tuple3 a b c) 
(NormalForm a, NormalForm b, NormalForm c) => NormalForm (Tuple3 a b c) 
Thdable (Tuple3 a b c) 
Sndable (Tuple3 a b c) 
Fstable (Tuple3 a b c) 
(Hashable a, Hashable b, Hashable c) => Hashable (Tuple3 a b c) 
type NthTy 1 (Tuple3 a b c) = a 
type NthTy 2 (Tuple3 a b c) = b 
type NthTy 3 (Tuple3 a b c) = c 
type Rep (Tuple3 a b c) 
type ProductThird (Tuple3 a b c) = c 
type ProductSecond (Tuple3 a b c) = b 
type ProductFirst (Tuple3 a b c) = a 

data Tuple4 a b c d

Strict tuple (a,b,c,d)

Constructors

Tuple4 !a !b !c !d 

Instances

Nthable 1 (Tuple4 a b c d) 
Nthable 2 (Tuple4 a b c d) 
Nthable 3 (Tuple4 a b c d) 
Nthable 4 (Tuple4 a b c d) 
(Eq a, Eq b, Eq c, Eq d) => Eq (Tuple4 a b c d) 
(Data a, Data b, Data c, Data d) => Data (Tuple4 a b c d) 
(Ord a, Ord b, Ord c, Ord d) => Ord (Tuple4 a b c d) 
(Show a, Show b, Show c, Show d) => Show (Tuple4 a b c d) 
Generic (Tuple4 a b c d) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d) => NormalForm (Tuple4 a b c d) 
Thdable (Tuple4 a b c d) 
Sndable (Tuple4 a b c d) 
Fstable (Tuple4 a b c d) 
(Hashable a, Hashable b, Hashable c, Hashable d) => Hashable (Tuple4 a b c d) 
type NthTy 1 (Tuple4 a b c d) = a 
type NthTy 2 (Tuple4 a b c d) = b 
type NthTy 3 (Tuple4 a b c d) = c 
type NthTy 4 (Tuple4 a b c d) = d 
type Rep (Tuple4 a b c d) 
type ProductThird (Tuple4 a b c d) = c 
type ProductSecond (Tuple4 a b c d) = b 
type ProductFirst (Tuple4 a b c d) = a 

class Fstable a where

Class of product types that have a first element

Associated Types

type ProductFirst a

Methods

fst :: a -> ProductFirst a

Instances

Fstable (a, b) 
Fstable (Tuple2 a b) 
Fstable (a, b, c) 
Fstable (Tuple3 a b c) 
Fstable (a, b, c, d) 
Fstable (Tuple4 a b c d) 

class Sndable a where

Class of product types that have a second element

Associated Types

type ProductSecond a

Methods

snd :: a -> ProductSecond a

Instances

Sndable (a, b) 
Sndable (Tuple2 a b) 
Sndable (a, b, c) 
Sndable (Tuple3 a b c) 
Sndable (a, b, c, d) 
Sndable (Tuple4 a b c d) 

class Thdable a where

Class of product types that have a third element

Associated Types

type ProductThird a

Methods

thd :: a -> ProductThird a

Instances

Thdable (a, b, c) 
Thdable (Tuple3 a b c) 
Thdable (a, b, c, d) 
Thdable (Tuple4 a b c d) 

id :: Category k cat => forall a. cat a a

the identity morphism

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 Nothing
False

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
""

either :: (a -> c) -> (b -> c) -> Either a b -> c

Case analysis for the Either type. If the value is Left a, apply the first function to a; if it is Right b, apply the second function to b.

Examples

We create two values of type Either String Int, one using the Left 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) s
3
>>> either length (*2) n
6

flip :: (a -> b -> c) -> b -> a -> c

flip f takes its (first) two arguments in the reverse order of f.

const :: a -> b -> a

Constant function.

error :: String -> a

putStr :: String -> IO ()

Print a string to standard output

putStrLn :: String -> IO ()

Print a string with a newline to standard output

getArgs :: IO [String]

Returns a list of the program's command line arguments (not including the program name).

uncurry :: (a -> b -> c) -> (a, b) -> c

uncurry converts a curried function to a function on pairs.

curry :: ((a, b) -> c) -> a -> b -> c

curry converts an uncurried function to a curried function.

swap :: (a, b) -> (b, a)

Swap the components of a pair.

until :: (a -> Bool) -> (a -> a) -> a -> a

until p f yields the result of applying f until p holds.

asTypeOf :: a -> a -> a

asTypeOf is a type-restricted version of const. It is usually used as an infix operator, and its typing forces its first argument (which is usually overloaded) to have the same type as the second.

undefined :: a

A special case of error. It is expected that compilers will recognize this and insert error messages which are more appropriate to the context in which undefined appears.

seq :: a -> b -> b

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.

class NormalForm a

Data that can be fully evaluated in Normal Form

Minimal complete definition

toNormalForm

Instances

NormalForm Bool 
NormalForm Char 
NormalForm Double 
NormalForm Float 
NormalForm Int 
NormalForm Int8 
NormalForm Int16 
NormalForm Int32 
NormalForm Int64 
NormalForm Integer 
NormalForm Word 
NormalForm Word8 
NormalForm Word16 
NormalForm Word32 
NormalForm Word64 
NormalForm () 
NormalForm Natural 
NormalForm CChar 
NormalForm CSChar 
NormalForm CUChar 
NormalForm CShort 
NormalForm CUShort 
NormalForm CInt 
NormalForm CUInt 
NormalForm CLong 
NormalForm CULong 
NormalForm CLLong 
NormalForm CULLong 
NormalForm CFloat 
NormalForm CDouble 
NormalForm String 
NormalForm IPv4 
NormalForm IPv6 
NormalForm UUID 
NormalForm a => NormalForm [a] 
NormalForm (Ptr a) 
NormalForm a => NormalForm (Maybe a) 
NormalForm (CountOf a) 
NormalForm (Offset a) 
NormalForm a => NormalForm (BE a) 
NormalForm a => NormalForm (LE a) 
NormalForm a => NormalForm (Array a) 
NormalForm (Block ty) 
NormalForm (UArray ty) 
NormalForm (ChunkedUArray ty) 
(NormalForm l, NormalForm r) => NormalForm (Either l r) 
(NormalForm a, NormalForm b) => NormalForm (a, b) 
(NormalForm a, NormalForm b) => NormalForm (These a b) 
(NormalForm a, NormalForm b) => NormalForm (Tuple2 a b) 
(NormalForm a, NormalForm b, NormalForm c) => NormalForm (a, b, c) 
(NormalForm a, NormalForm b, NormalForm c) => NormalForm (Tuple3 a b c) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d) => NormalForm (a, b, c, d) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d) => NormalForm (Tuple4 a b c d) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d, NormalForm e) => NormalForm (a, b, c, d, e) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d, NormalForm e, NormalForm f) => NormalForm (a, b, c, d, e, f) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d, NormalForm e, NormalForm f, NormalForm g) => NormalForm (a, b, c, d, e, f, g) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d, NormalForm e, NormalForm f, NormalForm g, NormalForm h) => NormalForm (a, b, c, d, e, f, g, h) 

deepseq :: NormalForm a => a -> b -> b

force :: NormalForm a => a -> a

Type classes

class Show a

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 show is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used.
  • If the constructor is defined to be an infix operator, then showsPrec will produce infix applications of the constructor.
  • the representation will be enclosed in parentheses if the precedence of the top-level constructor in x is less than d (associativity is ignored). Thus, if d is 0 then the result is never surrounded in parentheses; if d is 11 it is always surrounded in parentheses, unless it is an atomic expression.
  • If the constructor is defined using record syntax, then show will produce the record-syntax form, with the fields given in the same order as the original declaration.

For example, given the declarations

infixr 5 :^:
data Tree a =  Leaf a  |  Tree a :^: Tree a

the derived instance of Show is equivalent to

instance (Show a) => Show (Tree a) where

       showsPrec d (Leaf m) = showParen (d > app_prec) $
            showString "Leaf " . showsPrec (app_prec+1) m
         where app_prec = 10

       showsPrec d (u :^: v) = showParen (d > up_prec) $
            showsPrec (up_prec+1) u .
            showString " :^: "      .
            showsPrec (up_prec+1) v
         where up_prec = 5

Note that right-associativity of :^: is ignored. For example,

  • show (Leaf 1 :^: Leaf 2 :^: Leaf 3) produces the string "Leaf 1 :^: (Leaf 2 :^: Leaf 3)".

Minimal complete definition

showsPrec | show

Instances

Show Bool 
Show Char 
Show Int 
Show Int8 
Show Int16 
Show Int32 
Show Int64 
Show Integer 
Show Ordering 
Show Word 
Show Word8 
Show Word16 
Show Word32 
Show Word64 
Show CallStack 
Show TypeRep 
Show () 
Show FD 
Show HandleType 
Show SomeNat 
Show SomeSymbol 
Show Natural 
Show DataType 
Show Constr 
Show DataRep 
Show ConstrRep 
Show Fixity 
Show Version 
Show GCStats 
Show HandlePosn 
Show IOMode 
Show PatternMatchFail 
Show RecSelError 
Show RecConError 
Show RecUpdError 
Show NoMethodError 
Show NonTermination 
Show NestedAtomically 
Show ThreadId 
Show BlockReason 
Show ThreadStatus 
Show CDev 
Show CIno 
Show CMode 
Show COff 
Show CPid 
Show CSsize 
Show CGid 
Show CNlink 
Show CUid 
Show CCc 
Show CSpeed 
Show CTcflag 
Show CRLim 
Show Fd 
Show BlockedIndefinitelyOnMVar 
Show BlockedIndefinitelyOnSTM 
Show Deadlock 
Show AllocationLimitExceeded 
Show AssertionFailed 
Show SomeAsyncException 
Show AsyncException 
Show ArrayException 
Show ExitCode 
Show IOErrorType 
Show Handle 
Show BufferMode 
Show Newline 
Show NewlineMode 
Show SeekMode 
Show WordPtr 
Show IntPtr 
Show CChar 
Show CSChar 
Show CUChar 
Show CShort 
Show CUShort 
Show CInt 
Show CUInt 
Show CLong 
Show CULong 
Show CLLong 
Show CULLong 
Show CFloat 
Show CDouble 
Show CPtrdiff 
Show CSize 
Show CWchar 
Show CSigAtomic 
Show CClock 
Show CTime 
Show CUSeconds 
Show CSUSeconds 
Show CIntPtr 
Show CUIntPtr 
Show CIntMax 
Show CUIntMax 
Show MaskingState 
Show IOException 
Show ErrorCall 
Show ArithException 
Show All 
Show Any 
Show Arity 
Show Fixity 
Show Associativity 
Show TyCon 
Show Fingerprint 
Show GeneralCategory 
Show Lexeme 
Show Number 
Show SomeException 
Show PartialError 
Show OutOfBound 
Show ValidationFailure 
Show Endianness 
Show String 
Show Encoding 
Show Seconds 
Show NanoSeconds 
Show Bitmap 
Show AsciiString 
Show FileName 
Show FilePath 
Show Relativity 
Show And 
Show Condition 
Show Arch 
Show OS 
Show IPv4 
Show IPv6 
Show UUID 
Show a => Show [a] 
(Integral a, Show a) => Show (Ratio a) 
Show (Ptr a) 
Show (FunPtr a) 
Show (U1 p) 
Show p => Show (Par1 p) 
Show a => Show (Identity a)

This instance would be equivalent to the derived instances of the Identity newtype if the runIdentity field were removed

Show a => Show (ZipList a) 
Show (ForeignPtr a) 
Show a => Show (Dual a) 
Show a => Show (Sum a) 
Show a => Show (Product a) 
Show a => Show (First a) 
Show a => Show (Last a) 
Show a => Show (Maybe a) 
Show (FinalPtr a) 
Show (CountOf ty) 
Show (Offset ty) 
Show a => Show (NonEmpty a) 
Show a => Show (BE a) 
Show a => Show (LE a) 
Show a => Show (Array a) 
(PrimType ty, Show ty) => Show (Block ty) 
(PrimType ty, Show ty) => Show (UArray ty) 
(Show ty, PrimType ty) => Show (ChunkedUArray ty) 
Show a => Show (DList a) 
Show (ParseError input) 
(Show a, Show b) => Show (Either a b) 
Show (f p) => Show (Rec1 f p) 
(Show a, Show b) => Show (a, b) 
(Ix a, Show a, Show b) => Show (Array a b) 
Show a => Show (Const a b) 
Show (Proxy k s) 
Show (ST s a) 
(Show a, Show b) => Show (These a b) 
Show k => Show (Result input k) 
(Show a, Show b) => Show (Tuple2 a b) 
Show c => Show (K1 i c p) 
(Show (f p), Show (g p)) => Show ((:+:) f g p) 
(Show (f p), Show (g p)) => Show ((:*:) f g p) 
Show (f (g p)) => Show ((:.:) f g p) 
(Show a, Show b, Show c) => Show (a, b, c) 
Show (f a) => Show (Alt k f a) 
Show (Coercion k a b) 
Show ((:~:) k a b) 
(Show a, Show b, Show c) => Show (Tuple3 a b c) 
Show (f p) => Show (M1 i c f p) 
(Show a, Show b, Show c, Show d) => Show (a, b, c, d) 
(Show a, Show b, Show c, Show d) => Show (Tuple4 a b c d) 
(Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) 
(Show a, Show b, Show c, Show d, Show e, Show f) => Show (a, b, c, d, e, f) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g) => Show (a, b, c, d, e, f, g) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) => Show (a, b, c, d, e, f, g, h) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i) => Show (a, b, c, d, e, f, g, h, i) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j) => Show (a, b, c, d, e, f, g, h, i, j) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k) => Show (a, b, c, d, e, f, g, h, i, j, k) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l) => Show (a, b, c, d, e, f, g, h, i, j, k, l) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n, Show o) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) 

show :: Show a => a -> String

Use the Show class to create a String.

Note that this is not efficient, since an intermediate [Char] is going to be created before turning into a real String.

class Eq a => Ord a where

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.

Minimal complete definition

compare | (<=)

Methods

compare :: a -> a -> Ordering

(<) :: a -> a -> Bool infix 4

(<=) :: a -> a -> Bool infix 4

(>) :: a -> a -> Bool infix 4

(>=) :: a -> a -> Bool infix 4

max :: a -> a -> a

min :: a -> a -> a

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 BigNat 
Ord SomeNat 
Ord SomeSymbol 
Ord Natural 
Ord Version 
Ord IOMode 
Ord ThreadId 
Ord BlockReason 
Ord ThreadStatus 
Ord CDev 
Ord CIno 
Ord CMode 
Ord COff 
Ord CPid 
Ord CSsize 
Ord CGid 
Ord CNlink 
Ord CUid 
Ord CCc 
Ord CSpeed 
Ord CTcflag 
Ord CRLim 
Ord Fd 
Ord AsyncException 
Ord ArrayException 
Ord ExitCode 
Ord BufferMode 
Ord Newline 
Ord NewlineMode 
Ord SeekMode 
Ord WordPtr 
Ord IntPtr 
Ord CChar 
Ord CSChar 
Ord CUChar 
Ord CShort 
Ord CUShort 
Ord CInt 
Ord CUInt 
Ord CLong 
Ord CULong 
Ord CLLong 
Ord CULLong 
Ord CFloat 
Ord CDouble 
Ord CPtrdiff 
Ord CSize 
Ord CWchar 
Ord CSigAtomic 
Ord CClock 
Ord CTime 
Ord CUSeconds 
Ord CSUSeconds 
Ord CIntPtr 
Ord CUIntPtr 
Ord CIntMax 
Ord CUIntMax 
Ord ErrorCall 
Ord ArithException 
Ord All 
Ord Any 
Ord Arity 
Ord Fixity 
Ord Associativity 
Ord TyCon 
Ord Fingerprint 
Ord GeneralCategory 
Ord String 
Ord Encoding 
Ord Seconds 
Ord NanoSeconds 
Ord Bitmap 
Ord AsciiString 
Ord FilePath 
Ord Arch 
Ord OS 
Ord IPv4 
Ord IPv6 
Ord UUID 
Ord a => Ord [a] 
Integral a => Ord (Ratio a) 
Ord (Ptr a) 
Ord (FunPtr a) 
Ord (U1 p) 
Ord p => Ord (Par1 p) 
Ord a => Ord (Identity a) 
Ord a => Ord (ZipList a) 
Ord (ForeignPtr 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 (Maybe a) 
Ord (FinalPtr a) 
Ord (CountOf ty) 
Ord (Offset ty) 
(ByteSwap a, Ord a) => Ord (BE a) 
(ByteSwap a, Ord a) => Ord (LE a) 
Ord a => Ord (Array a) 
(PrimType ty, Ord ty) => Ord (Block ty) 
(PrimType ty, Ord ty) => Ord (UArray ty) 
(Ord ty, PrimType ty) => Ord (ChunkedUArray ty) 
Ord a => Ord (DList a) 
(Ord a, Ord b) => Ord (Either a b) 
Ord (f p) => Ord (Rec1 f p) 
(Ord a, Ord b) => Ord (a, b) 
(Ix i, Ord e) => Ord (Array i e) 
Ord a => Ord (Const a b) 
Ord (Proxy k s) 
(Ord a, Ord b) => Ord (These a b) 
(Ord a, Ord b) => Ord (Tuple2 a b) 
Ord c => Ord (K1 i c p) 
(Ord (f p), Ord (g p)) => Ord ((:+:) f g p) 
(Ord (f p), Ord (g p)) => Ord ((:*:) f g p) 
Ord (f (g p)) => Ord ((:.:) f g p) 
(Ord a, Ord b, Ord c) => Ord (a, b, c) 
Ord (f a) => Ord (Alt k f a) 
Ord (Coercion k a b) 
Ord ((:~:) k a b) 
(Ord a, Ord b, Ord c) => Ord (Tuple3 a b c) 
Ord (f p) => Ord (M1 i c f p) 
(Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d) 
(Ord a, Ord b, Ord c, Ord d) => Ord (Tuple4 a b c d) 
(Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e) 
(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) 

class Eq a where

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.

Minimal complete definition: either == or /=.

Minimal complete definition

(==) | (/=)

Methods

(==) :: a -> a -> Bool infix 4

(/=) :: a -> a -> Bool infix 4

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 CallStack 
Eq TypeRep 
Eq () 
Eq BigNat 
Eq SpecConstrAnnotation 
Eq SomeNat 
Eq SomeSymbol 
Eq Natural 
Eq Constr

Equality of constructors

Eq DataRep 
Eq ConstrRep 
Eq Fixity 
Eq Version 
Eq HandlePosn 
Eq IOMode 
Eq ThreadId 
Eq BlockReason 
Eq ThreadStatus 
Eq CDev 
Eq CIno 
Eq CMode 
Eq COff 
Eq CPid 
Eq CSsize 
Eq CGid 
Eq CNlink 
Eq CUid 
Eq CCc 
Eq CSpeed 
Eq CTcflag 
Eq CRLim 
Eq Fd 
Eq Errno 
Eq AsyncException 
Eq ArrayException 
Eq ExitCode 
Eq IOErrorType 
Eq Handle 
Eq BufferMode 
Eq Newline 
Eq NewlineMode 
Eq IODeviceType 
Eq SeekMode 
Eq WordPtr 
Eq IntPtr 
Eq CChar 
Eq CSChar 
Eq CUChar 
Eq CShort 
Eq CUShort 
Eq CInt 
Eq CUInt 
Eq CLong 
Eq CULong 
Eq CLLong 
Eq CULLong 
Eq CFloat 
Eq CDouble 
Eq CPtrdiff 
Eq CSize 
Eq CWchar 
Eq CSigAtomic 
Eq CClock 
Eq CTime 
Eq CUSeconds 
Eq CSUSeconds 
Eq CIntPtr 
Eq CUIntPtr 
Eq CIntMax 
Eq CUIntMax 
Eq MaskingState 
Eq IOException 
Eq ErrorCall 
Eq ArithException 
Eq All 
Eq Any 
Eq Arity 
Eq Fixity 
Eq Associativity 
Eq TyCon 
Eq Fingerprint 
Eq GeneralCategory 
Eq Lexeme 
Eq Number 
Eq PartialError 
Eq Sign 
Eq ValidationFailure 
Eq Endianness 
Eq String 
Eq Encoding 
Eq Seconds 
Eq NanoSeconds 
Eq Bitmap 
Eq AsciiString 
Eq FileName 
Eq FilePath 
Eq Relativity 
Eq And 
Eq Condition 
Eq Arch 
Eq OS 
Eq IPv4 
Eq IPv6 
Eq UUID 
Eq a => Eq [a] 
Eq a => Eq (Ratio a) 
Eq (StablePtr a) 
Eq (Ptr a) 
Eq (FunPtr a) 
Eq (U1 p) 
Eq p => Eq (Par1 p) 
Eq a => Eq (Identity a) 
Eq a => Eq (ZipList a) 
Eq (TVar a) 
Eq (ForeignPtr a) 
Eq (IORef 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 (Maybe a) 
Eq (FinalPtr a) 
Eq (CountOf ty) 
Eq (Offset ty) 
Eq a => Eq (NonEmpty a) 
Eq a => Eq (BE a) 
Eq a => Eq (LE a) 
Eq a => Eq (Array a) 
(PrimType ty, Eq ty) => Eq (Block ty) 
(PrimType ty, Eq ty) => Eq (UArray ty) 
PrimType ty => Eq (ChunkedUArray ty) 
Eq a => Eq (DList a) 
(Eq a, Eq b) => Eq (Either a b) 
Eq (f p) => Eq (Rec1 f p) 
(Eq a, Eq b) => Eq (a, b) 
(Ix i, Eq e) => Eq (Array i e) 
Eq a => Eq (Const a b) 
Eq (Proxy k s) 
Eq (STRef s a) 
(Eq a, Eq b) => Eq (These a b) 
(Eq a, Eq b) => Eq (Tuple2 a b) 
Eq c => Eq (K1 i c p) 
(Eq (f p), Eq (g p)) => Eq ((:+:) f g p) 
(Eq (f p), Eq (g p)) => Eq ((:*:) f g p) 
Eq (f (g p)) => Eq ((:.:) f g p) 
(Eq a, Eq b, Eq c) => Eq (a, b, c) 
Eq (STArray s i e) 
Eq (f a) => Eq (Alt k f a) 
Eq (Coercion k a b) 
Eq ((:~:) k a b) 
(Eq a, Eq b, Eq c) => Eq (Tuple3 a b c) 
Eq (f p) => Eq (M1 i c f p) 
(Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) 
(Eq a, Eq b, Eq c, Eq d) => Eq (Tuple4 a b c d) 
(Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e) 
(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) 

class Bounded a where

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.

Methods

minBound :: a

maxBound :: a

Instances

Bounded Bool 
Bounded Char 
Bounded Int 
Bounded Int8 
Bounded Int16 
Bounded Int32 
Bounded Int64 
Bounded Ordering 
Bounded Word 
Bounded Word8 
Bounded Word16 
Bounded Word32 
Bounded Word64 
Bounded () 
Bounded CDev 
Bounded CIno 
Bounded CMode 
Bounded COff 
Bounded CPid 
Bounded CSsize 
Bounded CGid 
Bounded CNlink 
Bounded CUid 
Bounded CTcflag 
Bounded CRLim 
Bounded Fd 
Bounded WordPtr 
Bounded IntPtr 
Bounded CChar 
Bounded CSChar 
Bounded CUChar 
Bounded CShort 
Bounded CUShort 
Bounded CInt 
Bounded CUInt 
Bounded CLong 
Bounded CULong 
Bounded CLLong 
Bounded CULLong 
Bounded CPtrdiff 
Bounded CSize 
Bounded CWchar 
Bounded CSigAtomic 
Bounded CIntPtr 
Bounded CUIntPtr 
Bounded CIntMax 
Bounded CUIntMax 
Bounded All 
Bounded Any 
Bounded GeneralCategory 
Bounded Encoding 
Bounded Seconds 
Bounded NanoSeconds 
Bounded Arch 
Bounded OS 
Bounded a => Bounded (Dual a) 
Bounded a => Bounded (Sum a) 
Bounded a => Bounded (Product a) 
(Bounded a, Bounded b) => Bounded (a, b) 
Bounded (Proxy k s) 
(Bounded a, Bounded b, Bounded c) => Bounded (a, b, c) 
Coercible k a b => Bounded (Coercion k a b) 
(~) k a b => Bounded ((:~:) k a b) 
(Bounded a, Bounded b, Bounded c, Bounded d) => Bounded (a, b, c, d) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded (a, b, c, d, e) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f) => Bounded (a, b, c, d, e, f) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g) => Bounded (a, b, c, d, e, f, g) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h) => Bounded (a, b, c, d, e, f, g, h) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i) => Bounded (a, b, c, d, e, f, g, h, i) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j) => Bounded (a, b, c, d, e, f, g, h, i, j) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k) => Bounded (a, b, c, d, e, f, g, h, i, j, k) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n) 
(Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n, Bounded o) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) 

class Enum a where

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:

   enumFrom     x   = enumFromTo     x maxBound
   enumFromThen x y = enumFromThenTo x y bound
     where
       bound | fromEnum y >= fromEnum x = maxBound
             | otherwise                = minBound

Minimal complete definition

toEnum, fromEnum

Methods

succ :: a -> a

the successor of a value. For numeric types, succ adds 1.

pred :: a -> a

the predecessor of a value. For numeric types, pred subtracts 1.

toEnum :: Int -> a

Convert from an Int.

fromEnum :: a -> Int

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.

enumFrom :: a -> [a]

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].

class Functor f where

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

fmap

Methods

fmap :: (a -> b) -> f a -> f b

(<$) :: a -> f b -> f a infixl 4

Replace all locations in the input with the same value. The default definition is fmap . const, but this may be overridden with a more efficient version.

Instances

Functor [] 
Functor IO 
Functor Id 
Functor P 
Functor Identity 
Functor ZipList 
Functor Handler 
Functor STM 
Functor First 
Functor Last 
Functor ReadP 
Functor Maybe 
Functor Partial 
Functor Array 
Functor DList 
Functor Gen 
Functor Check 
Functor ((->) r) 
Functor (Either a) 
Functor ((,) a) 
Functor (StateL s) 
Functor (StateR s) 
Ix i => Functor (Array i) 
Functor (Const m) 
Monad m => Functor (WrappedMonad m) 
Arrow a => Functor (ArrowMonad a) 
Functor (Proxy *) 
Functor (ST s) 
Functor (These a) 
Functor m => Functor (ResourceT m) 
Functor (MonadRandomState gen) 
Functor (Parser input) 
Functor (Result input) 
Arrow a => Functor (WrappedArrow a b) 
Functor f => Functor (Alt * f) 
Functor m => Functor (ReaderT r m) 
Functor m => Functor (StateT s m) 
Monad m => Functor (ZipSink i m) 
Functor (Conduit i o m) 
Monad state => Functor (Builder collection mutCollection step state err) 

class Fractional a where

Fractional Literal support

e.g. 1.2 :: Double 0.03 :: Float

Methods

fromRational :: Rational -> a

class Bifunctor p where

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:

bimap id idid

If you supply first and second, ensure:

first idid
second idid

If you supply both, you should also ensure:

bimap f g ≡ first f . second g

These ensure by parametricity:

bimap  (f . g) (h . i) ≡ bimap f h . bimap g i
first  (f . g) ≡ first  f . first  g
second (f . g) ≡ second f . second g

Since: 4.8.0.0

Minimal complete definition

bimap | first, second

Methods

bimap :: (a -> b) -> (c -> d) -> p a c -> p b d

Map over both arguments at the same time.

bimap f g ≡ first f . second g

first :: (a -> b) -> p a c -> p b c

Map covariantly over the first argument.

first f ≡ bimap f id

second :: (b -> c) -> p a b -> p a c

Map covariantly over the second argument.

secondbimap id

class Functor f => Applicative f where

A functor with application, providing operations to

  • embed pure expressions (pure), and
  • sequence computations and combine their results (<*>).

A minimal complete definition must include implementations of these functions satisfying the following laws:

identity
pure id <*> v = v
composition
pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
homomorphism
pure f <*> pure x = pure (f x)
interchange
u <*> pure y = 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).

Minimal complete definition

pure, (<*>)

Methods

pure :: a -> f a

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.

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.

(>>) :: m a -> m b -> m b infixl 1

Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.

return :: a -> m a

Inject a value into the monadic type.

fail :: String -> m a

Fail with a message. This operation is not part of the mathematical definition of a monad, but is invoked on pattern-match failure in a do expression.

Instances

Monad [] 
Monad IO 
Monad P 
Monad Identity 
Monad STM 
Monad First 
Monad Last 
Monad ReadP 
Monad Maybe 
Monad Partial 
Monad DList 
Monad Gen 
Monad Check 
Monad ((->) r) 
Monad (Either e) 
Monad m => Monad (WrappedMonad m) 
ArrowApply a => Monad (ArrowMonad a) 
Monad (Proxy *) 
Monad (ST s) 
Monad m => Monad (ResourceT m) 
Monad (MonadRandomState gen) 
ParserSource input => Monad (Parser input) 
Monad f => Monad (Alt * f) 
Monad m => Monad (ReaderT r m) 
(Functor m, Monad m) => Monad (StateT s m) 
Monad (Conduit i o m) 
Monad state => Monad (Builder collection mutCollection step state err) 

(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1

Same as >>=, but with the arguments interchanged.

class IsString a where

Class for string-like datastructures; used by the overloaded string extension (-XOverloadedStrings in GHC).

Methods

fromString :: String -> a

class IsList l where

The IsList class and its methods are intended to be used in conjunction with the OverloadedLists extension.

Since: 4.7.0.0

Minimal complete definition

fromList, toList

Associated Types

type Item l :: *

The Item type function returns the type of items of the structure l.

Methods

fromList :: [Item l] -> l

The fromList function constructs the structure l from the given list of Item l

fromListN :: Int -> [Item l] -> l

The fromListN function takes the input list's length as a hint. Its behaviour should be equivalent to fromList. The hint can be used to construct the structure l more efficiently compared to fromList. If the given hint does not equal to the input list's length the behaviour of fromListN is not specified.

toList :: l -> [Item l]

The toList function extracts a list of Item l from the structure l. It should satisfy fromList . toList = id.

Instances

Numeric type classes

class (Enum a, Eq a, Ord a, Integral a) => IsIntegral a where

Number literals, convertible through the generic Integer type.

all number are Enum'erable, meaning that you can move to next element

Methods

toInteger :: a -> Integer

class (Enum a, Eq a, Ord a, Integral a, IsIntegral a) => IsNatural a where

Non Negative Number literals, convertible through the generic Natural type

Methods

toNatural :: a -> Natural

class Signed a where

types that have sign and can be made absolute

Methods

abs :: a -> a

signum :: a -> Sign

class Additive a where

Represent class of things that can be added together, contains a neutral element and is commutative.

x + azero = x
azero + x = x
x + y = y + x

Minimal complete definition

azero, (+)

Methods

azero :: a

(+) :: a -> a -> a infixl 6

scale :: IsNatural n => n -> a -> a

class Subtractive a where

Represent class of things that can be subtracted.

Note that the result is not necessary of the same type as the operand depending on the actual type.

For example:

(-) :: Int -> Int -> Int
(-) :: DateTime -> DateTime -> Seconds
(-) :: Ptr a -> Ptr a -> PtrDiff
(-) :: Natural -> Natural -> Maybe Natural

Associated Types

type Difference a

Methods

(-) :: a -> a -> Difference a infixl 6

class Multiplicative a where

Represent class of things that can be multiplied together

x * midentity = x
midentity * x = x

Minimal complete definition

midentity, (*)

Methods

midentity :: a

Identity element over multiplication

(*) :: a -> a -> a infixl 7

Multiplication of 2 elements that result in another element

(^) :: (IsNatural n, IDivisible n) => a -> n -> a infixr 8

Raise to power, repeated multiplication e.g. > a ^ 2 = a * a > a ^ 10 = (a ^ 5) * (a ^ 5) .. (^) :: (IsNatural n) => a -> n -> a

class (Additive a, Multiplicative a) => IDivisible a where

Represent types that supports an euclidian division

(x ‘div‘ y) * y + (x ‘mod‘ y) == x

Minimal complete definition

div, mod | divMod

Methods

div :: a -> a -> a

mod :: a -> a -> a

divMod :: a -> a -> (a, a)

class Multiplicative a => Divisible a where

Support for division between same types

This is likely to change to represent specific mathematic divisions

Methods

(/) :: a -> a -> a infixl 7

Data types

data Maybe a :: * -> *

The Maybe type encapsulates an optional value. A value of type Maybe a either contains a value of type a (represented as Just a), or it is empty (represented as Nothing). 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.

Constructors

Nothing 
Just a 

Instances

Monad Maybe 
Functor Maybe 
Applicative Maybe 
Foldable Maybe 
Traversable Maybe 
Generic1 Maybe 
Alternative Maybe 
MonadPlus Maybe 
MonadFailure Maybe 
Eq a => Eq (Maybe a) 
Data a => Data (Maybe a) 
Ord a => Ord (Maybe a) 
Read a => Read (Maybe a) 
Show a => Show (Maybe a) 
Generic (Maybe a) 
Monoid a => Monoid (Maybe a)

Lift a semigroup into Maybe forming a Monoid according to http://en.wikipedia.org/wiki/Monoid: "Any semigroup S may be turned into a monoid simply by adjoining an element e not in S and defining e*e = e and e*s = s = s*e for all s ∈ S." Since there is no "Semigroup" typeclass providing just mappend, we use Monoid instead.

NormalForm a => NormalForm (Maybe a) 
Arbitrary a => Arbitrary (Maybe a) 
type Rep1 Maybe = D1 D1Maybe ((:+:) (C1 C1_0Maybe U1) (C1 C1_1Maybe (S1 NoSelector Par1))) 
type Failure Maybe = () 
type Rep (Maybe a) = D1 D1Maybe ((:+:) (C1 C1_0Maybe U1) (C1 C1_1Maybe (S1 NoSelector (Rec0 a)))) 
type (==) (Maybe k) a b = EqMaybe k a b 

data Ordering :: *

Constructors

LT 
EQ 
GT 

Instances

Bounded Ordering 
Enum Ordering 
Eq Ordering 
Data Ordering 
Ord Ordering 
Read Ordering 
Show Ordering 
Ix Ordering 
Generic Ordering 
Monoid Ordering 
type Rep Ordering = D1 D1Ordering ((:+:) (C1 C1_0Ordering U1) ((:+:) (C1 C1_1Ordering U1) (C1 C1_2Ordering U1))) 
type (==) Ordering a b = EqOrdering a b 

data Bool :: *

Constructors

False 
True 

Instances

data Char :: *

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).

data IO a :: * -> *

A value of type IO a is a computation which, when performed, does some I/O before returning a value of type a.

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.

data Either a b :: * -> * -> *

The Either type represents values with two possibilities: a value of type Either a b is either Left a or 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 Either String Int is the type of values which can be either a String 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
>>> s
Left "foo"
>>> let n = Right 3 :: Either String Int
>>> n
Right 3
>>> :type s
s :: Either String Int
>>> :type n
n :: 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) s
Left "foo"
>>> fmap (*2) n
Right 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)
>>> :}
>>> parseMultiple
Right 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)
>>> :}
>>> parseMultiple
Left "parse error"

Constructors

Left a 
Right b 

Instances

Bifunctor Either 
Monad (Either e) 
Functor (Either a) 
Applicative (Either e) 
Foldable (Either a) 
Traversable (Either a) 
Generic1 (Either a) 
MonadFailure (Either a) 
(Eq a, Eq b) => Eq (Either a b) 
(Data a, Data b) => Data (Either a b) 
(Ord a, Ord b) => Ord (Either a b) 
(Read a, Read b) => Read (Either a b) 
(Show a, Show b) => Show (Either a b) 
Generic (Either a b) 
(NormalForm l, NormalForm r) => NormalForm (Either l r) 
(Arbitrary l, Arbitrary r) => Arbitrary (Either l r) 
type Rep1 (Either a) = D1 D1Either ((:+:) (C1 C1_0Either (S1 NoSelector (Rec0 a))) (C1 C1_1Either (S1 NoSelector Par1))) 
type Failure (Either a) = a 
type Rep (Either a b) = D1 D1Either ((:+:) (C1 C1_0Either (S1 NoSelector (Rec0 a))) (C1 C1_1Either (S1 NoSelector (Rec0 b)))) 
type (==) (Either k k1) a b = EqEither k k1 a b 

Numbers

type Rational = Ratio Integer

Arbitrary-precision rational numbers, represented as a ratio of two Integer values. A rational number may be constructed using the % operator.

data Float :: *

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.

data Double :: *

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.

newtype CountOf ty

CountOf of a data structure.

More specifically, it represents the number of elements of type ty that fit into the data structure.

>>> length (fromList ['a', 'b', 'c', '🌟']) :: CountOf Char
CountOf 4

Same caveats as Offset apply here.

Constructors

CountOf Int 

newtype Offset ty

Offset in a data structure consisting of elements of type ty.

Int is a terrible backing type which is hard to get away from, considering that GHC/Haskell are mostly using this for offset. Trying to bring some sanity by a lightweight wrapping.

Constructors

Offset Int 

Collection types

data UArray ty

An array of type built on top of GHC primitive.

The elements need to have fixed sized and the representation is a packed contiguous array in memory that can easily be passed to foreign interface

Instances

PrimType ty => IsList (UArray ty) 
(PrimType ty, Eq ty) => Eq (UArray ty) 
Data ty => Data (UArray ty) 
(PrimType ty, Ord ty) => Ord (UArray ty) 
(PrimType ty, Show ty) => Show (UArray ty) 
PrimType ty => Monoid (UArray ty) 
NormalForm (UArray ty) 
PrimType ty => Buildable (UArray ty) 
PrimType ty => Fold1able (UArray ty) 
PrimType ty => Foldable (UArray ty) 
PrimType ty => IndexedCollection (UArray ty) 
PrimType ty => InnerFunctor (UArray ty) 
PrimType ty => Collection (UArray ty) 
PrimType ty => Sequential (UArray ty) 
PrimType ty => Zippable (UArray ty) 
PrimType ty => Copy (UArray ty) 
PrimType a => Hashable (UArray a) 
type Item (UArray ty) = ty 
type Element (UArray ty) = ty 
type Mutable (UArray ty) = MUArray ty 
type Step (UArray ty) = ty 

class Eq ty => PrimType ty

Represent the accessor for types that can be stored in the UArray and MUArray.

Types need to be a instance of storable and have fixed sized.

data Array a

Array of a

Instances

Functor Array 
Mappable Array 
IsList (Array ty) 
Eq a => Eq (Array a) 
Data ty => Data (Array ty) 
Ord a => Ord (Array a) 
Show a => Show (Array a) 
Monoid (Array a) 
NormalForm a => NormalForm (Array a) 
Buildable (Array ty) 
Fold1able (Array ty) 
Foldable (Array ty) 
IndexedCollection (Array ty) 
InnerFunctor (Array ty) 
Collection (Array ty) 
Sequential (Array ty) 
BoxedZippable (Array ty) 
Zippable (Array ty) 
Copy (Array ty) 
type Item (Array ty) = ty 
type Element (Array ty) = ty 
type Mutable (Array ty) = MArray ty 
type Step (Array ty) = ty 

Numeric functions

(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8

raise a number to an integral power

fromIntegral :: (Integral a, Num b) => a -> b

general coercion from integral types

realToFrac :: (Real a, Fractional b) => a -> b

general coercion to fractional types

Monoids

class Monoid a where

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 = foldr mappend 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.

Minimal complete definition

mempty, mappend

Methods

mempty :: a

Identity of mappend

mappend :: a -> a -> a

An associative operation

mconcat :: [a] -> a

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 String 
Monoid Builder 
Monoid Bitmap 
Monoid AsciiString 
Monoid FileName 
Monoid [a] 
Ord a => Monoid (Max a) 
Ord a => Monoid (Min 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) 
Monoid a => Monoid (Maybe a)

Lift a semigroup into Maybe forming a Monoid according to http://en.wikipedia.org/wiki/Monoid: "Any semigroup S may be turned into a monoid simply by adjoining an element e not in S and defining e*e = e and e*s = s = s*e for all s ∈ S." Since there is no "Semigroup" typeclass providing just mappend, we use Monoid instead.

Monoid (CountOf ty) 
Monoid (Array a) 
PrimType ty => Monoid (Block ty) 
PrimType ty => Monoid (UArray ty) 
Monoid (ChunkedUArray a) 
Monoid (DList a) 
Monoid b => Monoid (a -> b) 
(Monoid a, Monoid b) => Monoid (a, b) 
Monoid a => Monoid (Const a b) 
Monoid (Proxy k s) 
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) 
Alternative f => Monoid (Alt * f 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) 

(<>) :: Monoid m => m -> m -> m infixr 6

An infix synonym for mappend.

Since: 4.5.0.0

Collection

class (IsList c, Item c ~ Element c) => Collection c where

A set of methods for ordered colection

Minimal complete definition

null, length, (elem | notElem), minimum, maximum, all, any

Methods

null :: c -> Bool

Check if a collection is empty

length :: c -> CountOf (Element c)

Length of a collection (number of Element c)

elem :: forall a. (Eq a, a ~ Element c) => Element c -> c -> Bool

Check if a collection contains a specific element

This is the inverse of notElem.

notElem :: forall a. (Eq a, a ~ Element c) => Element c -> c -> Bool

Check if a collection does *not* contain a specific element

This is the inverse of elem.

maximum :: forall a. (Ord a, a ~ Element c) => NonEmpty c -> Element c

Get the maximum element of a collection

minimum :: forall a. (Ord a, a ~ Element c) => NonEmpty c -> Element c

Get the minimum element of a collection

any :: (Element c -> Bool) -> c -> Bool

Determine is any elements of the collection satisfy the predicate

all :: (Element c -> Bool) -> c -> Bool

Determine is all elements of the collection satisfy the predicate

and :: (Collection col, Element col ~ Bool) => col -> Bool

Return True if all the elements in the collection are True

or :: (Collection col, Element col ~ Bool) => col -> Bool

Return True if at least one element in the collection is True

class (IsList c, Item c ~ Element c, Monoid c, Collection c) => Sequential c where

A set of methods for ordered colection

Methods

take :: CountOf (Element c) -> c -> c

Take the first @n elements of a collection

revTake :: CountOf (Element c) -> c -> c

Take the last @n elements of a collection

drop :: CountOf (Element c) -> c -> c

Drop the first @n elements of a collection

revDrop :: CountOf (Element c) -> c -> c

Drop the last @n elements of a collection

splitAt :: CountOf (Element c) -> c -> (c, c)

Split the collection at the @n'th elements

revSplitAt :: CountOf (Element c) -> c -> (c, c)

Split the collection at the @n'th elements from the end

splitOn :: (Element c -> Bool) -> c -> [c]

Split on a specific elements returning a list of colletion

break :: (Element c -> Bool) -> c -> (c, c)

Split a collection when the predicate return true

breakElem :: Eq (Element c) => Element c -> c -> (c, c)

Split a collection when the predicate return true

takeWhile :: (Element c -> Bool) -> c -> c

Return the longest prefix in the collection that satisfy the predicate

dropWhile :: (Element c -> Bool) -> c -> c

Return the longest prefix in the collection that satisfy the predicate

intersperse :: Element c -> c -> c

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"

intercalate :: Monoid (Item c) => Element c -> c -> Element c

intercalate xs xss is equivalent to (mconcat (intersperse xs xss)). It inserts the list xs in between the lists in xss and concatenates the result.

span :: (Element c -> Bool) -> c -> (c, c)

Split a collection while the predicate return true

filter :: (Element c -> Bool) -> c -> c

Filter all the elements that satisfy the predicate

partition :: (Element c -> Bool) -> c -> (c, c)

Partition the elements thtat satisfy the predicate and those that don't

reverse :: c -> c

Reverse a collection

uncons :: c -> Maybe (Element c, c)

Decompose a collection into its first element and the remaining collection. If the collection is empty, returns Nothing.

unsnoc :: c -> Maybe (c, Element c)

Decompose a collection into a collection without its last element, and the last element If the collection is empty, returns Nothing.

snoc :: c -> Element c -> c

Prepend an element to an ordered collection

cons :: Element c -> c -> c

Append an element to an ordered collection

find :: (Element c -> Bool) -> c -> Maybe (Element c)

Find an element in an ordered collection

sortBy :: (Element c -> Element c -> Ordering) -> c -> c

Sort an ordered collection using the specified order function

singleton :: Element c -> c

Create a collection with a single element

head :: NonEmpty c -> Element c

get the first element of a non-empty collection

last :: NonEmpty c -> Element c

get the last element of a non-empty collection

tail :: NonEmpty c -> c

Extract the elements after the first element of a non-empty collection.

init :: NonEmpty c -> c

Extract the elements before the last element of a non-empty collection.

replicate :: CountOf (Element c) -> Element c -> c

Create a collection where the element in parameter is repeated N time

isPrefixOf :: Eq (Element c) => c -> c -> Bool

Takes two collections and returns True iff the first collection is a prefix of the second.

isSuffixOf :: Eq (Element c) => c -> c -> Bool

Takes two collections and returns True iff the first collection is a suffix of the second.

isInfixOf :: Eq (Element c) => c -> c -> Bool

Takes two collections and returns True iff the first collection is an infix of the second.

stripPrefix :: Eq (Element c) => c -> c -> Maybe c

Try to strip a prefix from a collection

stripSuffix :: Eq (Element c) => c -> c -> Maybe c

Try to strip a suffix from a collection

data NonEmpty a

NonEmpty property for any Collection

Instances

Eq a => Eq (NonEmpty a) 
Show a => Show (NonEmpty a) 
Collection c => Collection (NonEmpty c) 
type Item (NonEmpty c) = Item c 
type Element (NonEmpty a) = Element a 

nonEmpty :: Collection c => c -> Maybe (NonEmpty c)

Smart constructor to create a NonEmpty collection

If the collection is empty, then Nothing is returned Otherwise, the collection is wrapped in the NonEmpty property

Folds

class Foldable collection where

Give the ability to fold a collection on itself

Minimal complete definition

foldl', foldr

Methods

foldl' :: (a -> Element collection -> a) -> a -> collection -> a

Left-associative fold of a structure.

In the case of lists, foldl, when applied to a binary operator, a starting value (typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right:

foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn

Note that to produce the outermost application of the operator the entire input list must be traversed. This means that foldl' will diverge if given an infinite list.

Note that Foundation only provides foldl', a strict version of foldl because the lazy version is seldom useful.

Left-associative fold of a structure with strict application of the operator.

foldr :: (Element collection -> a -> a) -> a -> collection -> a

Right-associative fold of a structure.

foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)

foldr' :: (Element collection -> a -> a) -> a -> collection -> a

Right-associative fold of a structure, but with strict application of the operator.

Maybe

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 Maybe b. If this is Nothing, no element is added on to the result list. If it is Just b, then b is included in the result list.

Examples

Using mapMaybe f x is a shortcut for catMaybes $ map f x in most cases:

>>> 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]

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

isJust :: Maybe a -> Bool

The isJust function returns True iff its argument is of the form Just _.

Examples

Basic usage:

>>> isJust (Just 3)
True
>>> isJust (Just ())
True
>>> isJust Nothing
False

Only the outer constructor is taken into consideration:

>>> isJust (Just Nothing)
True

isNothing :: Maybe a -> Bool

The isNothing function returns True iff its argument is Nothing.

Examples

Basic usage:

>>> isNothing (Just 3)
False
>>> isNothing (Just ())
False
>>> isNothing Nothing
True

Only the outer constructor is taken into consideration:

>>> isNothing (Just Nothing)
False

listToMaybe :: [a] -> Maybe a

The listToMaybe function returns Nothing on an empty list or Just a where a is the first element of the list.

Examples

Basic usage:

>>> listToMaybe []
Nothing
>>> listToMaybe [9]
Just 9
>>> listToMaybe [1,2,3]
Just 1

Composing maybeToList with listToMaybe should be the identity on singleton/empty lists:

>>> maybeToList $ listToMaybe [5]
[5]
>>> maybeToList $ listToMaybe []
[]

But not on lists with more than one element:

>>> maybeToList $ listToMaybe [1,2,3]
[1]

maybeToList :: Maybe a -> [a]

The maybeToList function returns an empty list when given Nothing or a singleton list when not given Nothing.

Examples

Basic usage:

>>> maybeToList (Just 7)
[7]
>>> maybeToList Nothing
[]

One can use maybeToList to avoid pattern matching when combined with a function that (safely) works on lists:

>>> import Text.Read ( readMaybe )
>>> sum $ maybeToList (readMaybe "3")
3
>>> sum $ maybeToList (readMaybe "")
0

Either

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 partitionEithers x should be the same pair as (lefts x, rights x):

>>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]
>>> partitionEithers list == (lefts list, rights list)
True

lefts :: [Either a b] -> [a]

Extracts from a list of Either all the Left elements. All the Left elements are extracted in order.

Examples

Basic usage:

>>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]
>>> lefts list
["foo","bar","baz"]

rights :: [Either a b] -> [b]

Extracts from a list of Either all the Right elements. All the Right elements are extracted in order.

Examples

Basic usage:

>>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]
>>> rights list
[3,7]

Function

on :: (b -> b -> c) -> (a -> b) -> a -> a -> c infixl 0

(*) `on` f = \x y -> f x * f y.

Typical usage: sortBy (compare `on` fst).

Algebraic properties:

  • (*) `on` id = (*) (if (*) ∉ {⊥, const ⊥})
  • ((*) `on` f) `on` g = (*) `on` (f . g)
  • flip on f . flip on g = flip on (g . f)

Applicative

(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4

An infix synonym for fmap.

Examples

Convert from a Maybe Int to a Maybe String using show:

>>> show <$> Nothing
Nothing
>>> show <$> Just 3
Just "3"

Convert from an Either Int Int to an Either Int String using show:

>>> show <$> Left 17
Left 17
>>> show <$> Right 17
Right "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)

(<|>) :: Alternative f => forall a. f a -> f a -> f a

An associative binary operation

Monad

(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1

Left-to-right Kleisli composition of monads.

Exceptions

class (Typeable * e, Show e) => Exception e where

Any type that you wish to throw or catch as an exception must be an instance of the Exception class. The simplest case is a new exception type directly below the root:

data MyException = ThisException | ThatException
    deriving (Show, Typeable)

instance Exception MyException

The default method definitions in the Exception class do what we need in this case. You can now throw and catch ThisException and ThatException as exceptions:

*Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException))
Caught ThisException

In more complicated examples, you may wish to define a whole hierarchy of exceptions:

---------------------------------------------------------------------
-- Make the root exception type for all the exceptions in a compiler

data SomeCompilerException = forall e . Exception e => SomeCompilerException e
    deriving Typeable

instance Show SomeCompilerException where
    show (SomeCompilerException e) = show e

instance Exception SomeCompilerException

compilerExceptionToException :: Exception e => e -> SomeException
compilerExceptionToException = toException . SomeCompilerException

compilerExceptionFromException :: Exception e => SomeException -> Maybe e
compilerExceptionFromException x = do
    SomeCompilerException a <- fromException x
    cast a

---------------------------------------------------------------------
-- Make a subhierarchy for exceptions in the frontend of the compiler

data SomeFrontendException = forall e . Exception e => SomeFrontendException e
    deriving Typeable

instance Show SomeFrontendException where
    show (SomeFrontendException e) = show e

instance Exception SomeFrontendException where
    toException = compilerExceptionToException
    fromException = compilerExceptionFromException

frontendExceptionToException :: Exception e => e -> SomeException
frontendExceptionToException = toException . SomeFrontendException

frontendExceptionFromException :: Exception e => SomeException -> Maybe e
frontendExceptionFromException x = do
    SomeFrontendException a <- fromException x
    cast a

---------------------------------------------------------------------
-- Make an exception type for a particular frontend compiler exception

data MismatchedParentheses = MismatchedParentheses
    deriving (Typeable, Show)

instance Exception MismatchedParentheses where
    toException   = frontendExceptionToException
    fromException = frontendExceptionFromException

We can now catch a MismatchedParentheses exception as MismatchedParentheses, SomeFrontendException or SomeCompilerException, but not other types, e.g. IOException:

*Main> throw MismatchedParentheses catch e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses catch e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses catch e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses catch e -> putStrLn ("Caught " ++ show (e :: IOException))
*** Exception: MismatchedParentheses

Minimal complete definition

Nothing

Methods

toException :: e -> SomeException

fromException :: SomeException -> Maybe e

displayException :: e -> String

Render this exception value in a human-friendly manner.

Default implementation: show.

Since: 4.8.0.0

class Typeable a

The class Typeable allows a concrete representation of a type to be calculated.

Minimal complete definition

typeRep#

data SomeException :: *

The SomeException type is the root of the exception type hierarchy. When an exception of type e is thrown, behind the scenes it is encapsulated in a SomeException.

data IOException :: *

Exceptions that occur in the IO monad. An IOException records a more specific error type, a descriptive string and maybe the handle that was used when the error was flagged.

Proxy

data Proxy t :: k -> *

A concrete, poly-kinded proxy type

Constructors

Proxy 

Instances

Monad (Proxy *) 
Functor (Proxy *) 
Applicative (Proxy *) 
Foldable (Proxy *) 
Traversable (Proxy *) 
Bounded (Proxy k s) 
Enum (Proxy k s) 
Eq (Proxy k s) 
Data t => Data (Proxy * t) 
Ord (Proxy k s) 
Read (Proxy k s) 
Show (Proxy k s) 
Ix (Proxy k s) 
Generic (Proxy * t) 
Monoid (Proxy k s) 
type Rep (Proxy k t) = D1 D1Proxy (C1 C1_0Proxy U1) 

asProxyTypeOf :: a -> Proxy * a -> a

asProxyTypeOf is a type-restricted version of const. It is usually used as an infix operator, and its typing forces its first argument (which is usually overloaded) to have the same type as the tag of the second.

Partial

data Partial a

Partialiality wrapper.

partial :: a -> Partial a

Create a value that is partial. this can only be unwrap using the fromPartial function

data PartialError

An error related to the evaluation of a Partial value that failed.

it contains the name of the function and the reason for failure

fromPartial :: Partial a -> a

Dewrap a possible partial value

ifThenElse :: Bool -> a -> a -> a

for support of if .. then .. else

Old Prelude Strings as [Char] with bridge back and forth

type LString = String

Alias to Prelude String ([Char]) for compatibility purpose