subhask-0.1.0.0: Type safe interface for programming in subcategories of Hask

Safe HaskellNone
LanguageHaskell2010

SubHask

Contents

Description

This module reexports the modules that every program using SubHask will need. You should import it instead of Prelude.

Synopsis

Documentation

classes

class Show a where

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

Methods

showsPrec

Arguments

:: Int

the operator precedence of the enclosing context (a number from 0 to 11). Function application has precedence 10.

-> a

the value to be converted to a String

-> ShowS 

Convert a value to a readable String.

showsPrec should satisfy the law

showsPrec d x r ++ s  ==  showsPrec d x (r ++ s)

Derived instances of Read and Show satisfy the following:

That is, readsPrec parses the string produced by showsPrec, and delivers the value that showsPrec started with.

show :: a -> String

A specialised variant of showsPrec, using precedence context zero, and returning an ordinary String.

showList :: [a] -> ShowS

The method showList is provided to allow the programmer to give a specialised way of showing lists of values. For example, this is used by the predefined Show instance of the Char type, where values of type String should be shown in double quotes, rather than between square brackets.

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 TypeRep 
Show Exp 
Show Match 
Show Clause 
Show Pat 
Show Type 
Show Dec 
Show Name 
Show FunDep 
Show TyVarBndr 
Show () 
Show QCGen 
Show ByteString 
Show ByteString 
Show Buffer 
Show Buffer 
Show Pos 
Show More 
Show Void 
Show SomeNat 
Show SomeSymbol 
Show Natural 
Show Version 
Show PatternMatchFail 
Show RecSelError 
Show RecConError 
Show RecUpdError 
Show NoMethodError 
Show NonTermination 
Show NestedAtomically 
Show ThreadId 
Show BlockReason 
Show ThreadStatus 
Show BlockedIndefinitelyOnMVar 
Show BlockedIndefinitelyOnSTM 
Show Deadlock 
Show AllocationLimitExceeded 
Show AssertionFailed 
Show SomeAsyncException 
Show AsyncException 
Show ArrayException 
Show ExitCode 
Show IOErrorType 
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 Lexeme 
Show Number 
Show SomeException 
Show ShortByteString 
Show EncodeOptions 
Show IntSet 
Show MatrixOrder 
Show Config 
Show Builder 
Show Con 
Show Doc 
Show TextDetails 
Show Style 
Show Mode 
Show Doc 
Show ModName 
Show PkgName 
Show Module 
Show OccName 
Show Loc 
Show Info 
Show ModuleInfo 
Show Fixity 
Show FixityDirection 
Show Lit 
Show Body 
Show Guard 
Show Stmt 
Show Range 
Show TySynEqn 
Show FamFlavour 
Show Foreign 
Show Callconv 
Show Safety 
Show Pragma 
Show Inline 
Show RuleMatch 
Show Phases 
Show RuleBndr 
Show AnnTarget 
Show Strict 
Show TyLit 
Show Role 
Show AnnLookup 
Show Padding 
Show DateFormatSpec 
Show LocalTime 
Show ZonedTime 
Show TimeOfDay 
Show TimeZone 
Show NominalDiffTime 
Show POrdering 
Show K3 
Show H3 
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 (Mass a) 
Show a => Show (Approximate a) 
Show (ForeignPtr a) 
Show a => Show (Maybe a) 
Show a => Show (Identity a)

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

HasResolution a => Show (Fixed a) 
Show a => Show (Complex a) 
Show a => Show (ZipList 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 (Down a) 
Show a => Show (Decoder a) 
Show (Bloom a) 
Show n => Show (VarInt n) 
Show a => Show (Only a) 
Show r => Show (Result r) 
(Show a, Storable a) => Show (Vector a) 
Show a => Show (IntMap a) 
Show a => Show (Set a) 
Show a => Show (Tree a) 
Show a => Show (Seq a) 
Show a => Show (ViewL a) 
Show a => Show (ViewR a) 
Show a => Show (Vector a) 
(Show a, Prim a) => Show (Vector a) 
Show a => Show (HashSet a) 
(Floating a, Show a) => Show (Log a) 
Show a => Show (Min a) 
Show a => Show (Max a) 
Show a => Show (First a) 
Show a => Show (Last a) 
Show m => Show (WrappedMonoid m) 
Show a => Show (Option a) 
Show a => Show (NonEmpty a) 
Show a => Show (WithPreludeOrd a) 
Show t0 => Show (NonNegative t) 
Show (Z n0) => Show (VedicSquare n) 
(Show v, Show (Scalar v)) => Show (Ball v) 
Show (Z (Order a0)) => Show (ZIndex a) 
Show e => Show (BArray e) 
(Unbox e, Show e) => Show (UArray e) 
Show a => Show (Forward a) 
Show v => Show (Box v) 
Show a0 => Show (Jaccard a) 
Show a0 => Show (Hamming a) 
Show a0 => Show (Levenshtein a) 
Show s0 => Show (Uncompensated s) 
Show a0 => Show (Lexical a) 
Show a0 => Show (ComponentWise a) 
Show r0 => Show (Goedel_ r) 
Show b0 => Show (Boolean2Ring b) 
Show a => Show (Seq a) 
Show e => Show (IntMap e) 
Show e => Show (IntMap' e) 
Show a => Show (Set a) 
Show a => Show (LexSet a) 
Show (ByteString Char) 
Show a0 => Show (PartitionOnNewline a) 
(Show a, Show b) => Show (Either a b) 
Show (f p) => Show (Rec1 f p) 
(Show a, Show b) => Show (a, b) 
Show (ST s a) 
(Ix ix, Show ix, Show e, IArray UArray e) => Show (UArray ix e) 
(Ix a, Show a, Show b) => Show (Array a b) 
(Show i, Show r) => Show (IResult i r) 
Show a => Show (Const a b) 
Show (Proxy k s) 
Show (MBloom s a) 
(Show1 f, Show a) => Show (IdentityT f a) 
(Show k, Show a) => Show (Map k a) 
(Show (f (Cofree f a)), Show a) => Show (Cofree f a) 
Show (HyperLogLog k p) 
Show (f a) => Show (Yoneda f a) 
(Show k, Show v) => Show (HashMap k v) 
(Show1 f, Show a) => Show (Backwards f a) 
(Show1 m, Show a) => Show (ListT m a) 
(Show1 m, Show a) => Show (MaybeT m a) 
(Show a, Show b) => Show (Arg a b) 
(Show1 g, Show a) => Show (Apply g a) 
(Show1 f, Show a) => Show (Reverse f a) 
Show a => Show (Constant a b) 
(Show a, IsMutable a, PrimBase m) => Show (Mutable m a) 
(Show x, Show y) => Show (Labeled' x y) 
Show (Z ((^) p0 k0)) => Show (Galois p k) 
(Eq r, Show r) => Show (Polynomial_ r r) 
(MatrixField (Scalar b), Show (Scalar b)) => Show ((+>) a b) 
(Show i, Show e) => Show (Map i e) 
(Show i, Show e) => Show (Map' i e) 
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 ((:~:) k a b) 
(Show (f a), Show (g a)) => Show (Coproduct f g a) 
(Functor f, Show1 f, Show1 g, Show a) => Show (Compose f g a) 
(Show e, Show1 m, Show a) => Show (ErrorT e m a) 
(Show e, Show1 m, Show a) => Show (ExceptT e m a) 
(Show w, Show1 m, Show a) => Show (WriterT w m a) 
(Show w, Show1 m, Show a) => Show (WriterT w m a) 
Show b => Show (Tagged k s b) 
(Show1 f, Show1 g, Show a) => Show (Product f g a) 
Show a0 => Show ((/) k a b) 
(Show r, ValidSVector Nat n r, KnownNat n) => Show (SVector Nat n r) 
(Show r, Monoid r, ValidSVector Symbol n r) => Show (SVector Symbol n r) 
(Show r, Monoid r, Prim r) => Show (UVector Symbol n r) 
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 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) 

class Read a where

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 Read instance 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 Read will parse only the record-syntax form, and furthermore, the fields must be given in the same order as the original declaration.
  • The derived Read instance 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 = 5

Note 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 = readListPrecDefault

Minimal complete definition

readsPrec | readPrec

Methods

readsPrec

Arguments

:: Int

the operator precedence of the enclosing context (a number from 0 to 11). Function application has precedence 10.

-> ReadS a 

attempts to parse a value from the front of the string, returning a list of (parsed value, remaining string) pairs. If there is no successful parse, the returned list is empty.

Derived instances of Read and Show satisfy the following:

That is, readsPrec parses the string produced by showsPrec, and delivers the value that showsPrec started with.

readList :: ReadS [a]

The method readList is provided to allow the programmer to give a specialised way of parsing lists of values. For example, this is used by the predefined Read instance of the Char type, where values of type String should be are expected to use double quotes, rather than square brackets.

Instances

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 QCGen 
Read ByteString 
Read ByteString 
Read Void

Reading a Void value is always a parse error, considering Void as a data type with no constructors.

Read SomeNat 
Read SomeSymbol 
Read Natural 
Read Version 
Read ExitCode 
Read WordPtr 
Read IntPtr 
Read CChar 
Read CSChar 
Read CUChar 
Read CShort 
Read CUShort 
Read CInt 
Read CUInt 
Read CLong 
Read CULong 
Read CLLong 
Read CULLong 
Read CFloat 
Read CDouble 
Read CPtrdiff 
Read CSize 
Read CWchar 
Read CSigAtomic 
Read CClock 
Read CTime 
Read CUSeconds 
Read CSUSeconds 
Read CIntPtr 
Read CUIntPtr 
Read CIntMax 
Read CUIntMax 
Read All 
Read Any 
Read Arity 
Read Fixity 
Read Associativity 
Read Lexeme 
Read ShortByteString 
Read IntSet 
Read POrdering 
Read K3 
Read H3 
Read a => Read [a] 
(Integral a, Read a) => Read (Ratio a) 
Read (U1 p) 
Read p => Read (Par1 p) 
Read a => Read (Mass a) 
Read a => Read (Approximate a) 
Read a => Read (Maybe a) 
Read a => Read (Identity a)

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

HasResolution a => Read (Fixed 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 a => Read (Only a) 
(Read a, Storable a) => Read (Vector a) 
Read e => Read (IntMap e) 
(Read a, Ord a) => Read (Set a) 
Read a => Read (Tree a) 
Read a => Read (Seq a) 
Read a => Read (ViewL a) 
Read a => Read (ViewR a) 
Read a => Read (Vector a) 
(Read a, Prim a) => Read (Vector a) 
(Eq a, Hashable a, Read a) => Read (HashSet a) 
(Floating a, Read a) => Read (Log a) 
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 a0 => Read (WithPreludeOrd a) 
Read t0 => Read (NonNegative t) 
Read (Z n0) => Read (VedicSquare n) 
(Read v, Read (Scalar v)) => Read (Ball v) 
Read (Z (Order a0)) => Read (ZIndex a) 
Read v => Read (Box v) 
Read a0 => Read (Jaccard a) 
Read a0 => Read (Hamming a) 
Read a0 => Read (Levenshtein a) 
Read s0 => Read (Uncompensated s) 
Read a0 => Read (Lexical a) 
Read a0 => Read (ComponentWise a) 
Read r0 => Read (Goedel_ r) 
Read b0 => Read (Boolean2Ring b) 
Read a => Read (Seq a) 
Read e => Read (IntMap e) 
Read e => Read (IntMap' e) 
Read (ByteString Char) 
Read a0 => Read (PartitionOnNewline a) 
(Read a, Read b) => 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 a => Read (Const a b) 
Read (Proxy k s) 
(Read1 f, Read a) => Read (IdentityT f a) 
(Ord k, Read k, Read e) => Read (Map k e) 
(Read (f (Cofree f a)), Read a) => Read (Cofree f a) 
(Functor f, Read (f a)) => Read (Yoneda f a) 
(Eq k, Hashable k, Read k, Read e) => Read (HashMap k e) 
(Read1 f, Read a) => Read (Backwards f a) 
(Read1 m, Read a) => Read (ListT m a) 
(Read1 m, Read a) => Read (MaybeT m a) 
(Read a, Read b) => Read (Arg a b) 
(Read1 g, Read a) => Read (Apply g a) 
(Read1 f, Read a) => Read (Reverse f a) 
Read a => Read (Constant a b) 
(Read x, Read y) => Read (Labeled' x y) 
Read (Z ((^) p0 k0)) => Read (Galois p k) 
Read c => Read (K1 i c p) 
(Read (f p), Read (g p)) => Read ((:+:) f g p) 
(Read (f p), Read (g p)) => Read ((:*:) f g p) 
Read (f (g p)) => Read ((:.:) f g p) 
(Read a, Read b, Read c) => Read (a, b, c) 
Read (f a) => Read (Alt k f a) 
(~) k a b => Read ((:~:) k a b) 
(Read (f a), Read (g a)) => Read (Coproduct f g a) 
(Functor f, Read1 f, Read1 g, Read a) => Read (Compose f g a) 
(Read e, Read1 m, Read a) => Read (ErrorT e m a) 
(Read e, Read1 m, Read a) => Read (ExceptT e m a) 
(Read w, Read1 m, Read a) => Read (WriterT w m a) 
(Read w, Read1 m, Read a) => Read (WriterT w m a) 
Read b => Read (Tagged k s b) 
(Read1 f, Read1 g, Read a) => Read (Product f g a) 
Read a0 => Read ((/) k a b) 
Read (f p) => Read (M1 i c f p) 
(Read a, Read b, Read c, Read d) => Read (a, b, c, d) 
(Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) 
(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) 

read :: Read a => String -> a

The read function reads input from a string, which must be completely consumed by the input process.

class Storable a where

The member functions of this class facilitate writing values of primitive types to raw memory (which may have been allocated with the above mentioned routines) and reading values from blocks of raw memory. The class, furthermore, includes support for computing the storage requirements and alignment restrictions of storable types.

Memory addresses are represented as values of type Ptr a, for some a which is an instance of class Storable. The type argument to Ptr helps provide some valuable type safety in FFI code (you can't mix pointers of different types without an explicit cast), while helping the Haskell type system figure out which marshalling method is needed for a given pointer.

All marshalling between Haskell and a foreign language ultimately boils down to translating Haskell data structures into the binary representation of a corresponding data structure of the foreign language and vice versa. To code this marshalling in Haskell, it is necessary to manipulate primitive data types stored in unstructured memory blocks. The class Storable facilitates this manipulation on all types for which it is instantiated, which are the standard basic types of Haskell, the fixed size Int types (Int8, Int16, Int32, Int64), the fixed size Word types (Word8, Word16, Word32, Word64), StablePtr, all types from Foreign.C.Types, as well as Ptr.

Minimal complete definition

sizeOf, alignment, (peek | peekElemOff | peekByteOff), (poke | pokeElemOff | pokeByteOff)

Methods

sizeOf :: a -> Int

Computes the storage requirements (in bytes) of the argument. The value of the argument is not used.

alignment :: a -> Int

Computes the alignment constraint of the argument. An alignment constraint x is fulfilled by any address divisible by x. The value of the argument is not used.

peekElemOff :: Ptr a -> Int -> IO a

Read a value from a memory area regarded as an array of values of the same kind. The first argument specifies the start address of the array and the second the index into the array (the first element of the array has index 0). The following equality holds,

peekElemOff addr idx = IOExts.fixIO $ \result ->
  peek (addr `plusPtr` (idx * sizeOf result))

Note that this is only a specification, not necessarily the concrete implementation of the function.

pokeElemOff :: Ptr a -> Int -> a -> IO ()

Write a value to a memory area regarded as an array of values of the same kind. The following equality holds:

pokeElemOff addr idx x = 
  poke (addr `plusPtr` (idx * sizeOf x)) x

peekByteOff :: Ptr b -> Int -> IO a

Read a value from a memory location given by a base address and offset. The following equality holds:

peekByteOff addr off = peek (addr `plusPtr` off)

pokeByteOff :: Ptr b -> Int -> a -> IO ()

Write a value to a memory location given by a base address and offset. The following equality holds:

pokeByteOff addr off x = poke (addr `plusPtr` off) x

peek :: Ptr a -> IO a

Read a value from the given memory location.

Note that the peek and poke functions might require properly aligned addresses to function correctly. This is architecture dependent; thus, portable code should ensure that when peeking or poking values of some type a, the alignment constraint for a, as given by the function alignment is fulfilled.

poke :: Ptr a -> a -> IO ()

Write the given value to the given memory location. Alignment restrictions might apply; see peek.

data types

type String = [Char]

A String is a list of characters. String constants in Haskell are values of type String.

type FilePath = String

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.

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 Int :: *

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 
Ix Int 
Generic Int 
Arbitrary Int 
CoArbitrary Int 
Storable Int 
Serial Int 
FromField Int

Accepts a signed decimal number. Ignores whitespace.

ToField Int

Uses decimal encoding with optional sign.

NFData Int 
Hashable Int 
Prim Int 
Unbox Int 
Lift Int 
IsMutable Int Source 
IxContainer Int Source 
Metric Int Source 
FiniteModule Int Source 
FreeModule Int Source 
Module Int Source 
Normed Int Source 
Integral Int Source 
Ring Int Source 
Rig Int Source 
Rg Int Source 
Abelian Int Source 
Group Int Source 
Cancellative Int Source 
Monoid Int Source 
Action Int Source 
Semigroup Int Source 
Bounded Int Source 
Ord_ Int Source 
Graded Int Source 
Enum Int Source 
Lattice_ Int Source 
MinBound_ Int Source 
POrd_ Int Source 
Eq_ Int Source 
IArray UArray Int 
Vector Vector Int 
MVector MVector Int 
QuotientField Double Int Source 
QuotientField Float Int Source 
QuotientField Rational Int Source 
Container Vector e => Konst e Int Vector 
Reifies * Z Int 
KnownNat n => Quotient Nat Int n Source 
Reifies * n Int => Reifies * (D n) Int 
Reifies * n Int => Reifies * (SD n) Int 
Reifies * n Int => Reifies * (PD n) Int 
Container Vector e => Konst e (Int, Int) Matrix 
Container Vector e => Build Int (e -> e) Vector e 
Constructible (UArray Int) Source 
Monoid (UArray Int) Source 
MArray (STUArray s) Int (ST s) 
Container Matrix e => Build (Int, Int) (e -> e -> e) Matrix e 
type Rep Int = D1 D_Int (C1 C_Int (S1 NoSelector (Rec0 Int))) 
type Unsigned Int = Word 
type Signed Int = Int 
data Vector Int = V_Int (Vector Int) 
type Index Int = Int Source 
type Index Int = Int Source 
type Elem Int = Int Source 
type Elem Int = Int Source 
type Scalar Int = Int Source 
type Actor Int = Int Source 
type Logic Int = Bool Source 
data MVector s Int = MV_Int (MVector s Int) 
data Mutable m Int = Mutable_ConT_GHC_Types_Int (PrimRef m Int) Source 
type ValidElem Int e = () 
type SetIndex Int a = Int Source 
type SetElem Int a = Int Source 
type (><) * * Int Int = Int Source 

data Int8 :: *

8-bit signed integer type

data Integer :: *

Invariant: Jn# and Jp# are used iff value doesn't fit in S#

Useful properties resulting from the invariants:

Instances

Enum Integer 
Eq Integer 
Integral Integer 
Num Integer 
Ord Integer 
Read Integer 
Real Integer 
Show Integer 
Ix Integer 
Arbitrary Integer 
CoArbitrary Integer 
Serial Integer
>>> (runGetL deserialize $ runPutL $ serialize (1822304234^100::Integer))::Integer
115368812579128172803867366576339947332796540054052185472042218522037227934707037623902492207671987696439966697503243972076991940820348847422930433939639982092916577692754723458548819441583937289395076910527534916776189405228720063994377687015476947534961767053653973945346259230972683338173842343243493433367681264359887291905132383269175086733345253389374961758293922003996035662362278340494093804835649459223465051596978792130073960666112508481814461273829244289795707398202762289955919352549768394583446336873179280924584333491364188425976869717125645749497258775598562132278030402205794994603544837805140410310712693778605743100915046769381631247123664460203591228745772887977959388457679427407639421147498028487544882346912935398848298806021505673449774474457435816552278997100556732447852816961683577731381792363312695347606768120122976105200574809419685234274705929886121600174028733812771637390342332436695318974693376
FromField Integer

Accepts a signed decimal number. Ignores whitespace.

ToField Integer

Uses decimal encoding with optional sign.

NFData Integer 
Hashable Integer 
Lift Integer 
IsMutable Integer Source 
IsMutable Rational Source 
IxContainer Integer Source 
IxContainer Rational Source 
Metric Integer Source 
Metric Rational Source 
TensorAlgebra Rational Source 
Banach Rational Source 
VectorSpace Rational Source 
FiniteModule Integer Source 
FiniteModule Rational Source 
FreeModule Integer Source 
FreeModule Rational Source 
Module Integer Source 
Module Rational Source 
Normed Integer Source 
Normed Rational Source 
RationalField Rational Source 
OrdField Rational Source 
Field Rational Source 
Integral Integer Source 
Ring Integer Source 
Ring Rational Source 
Rig Integer Source 
Rig Rational Source 
Rg Integer Source 
Rg Rational Source 
Abelian Integer Source 
Abelian Rational Source 
Group Integer Source 
Group Rational Source 
Cancellative Integer Source 
Cancellative Rational Source 
Monoid Integer Source 
Monoid Rational Source 
Action Integer Source 
Action Rational Source 
Semigroup Integer Source 
Semigroup Rational Source 
Ord_ Integer Source 
Ord_ Rational Source 
Graded Integer Source 
Enum Integer Source 
Lattice_ Integer Source 
Lattice_ Rational Source 
POrd_ Integer Source 
POrd_ Rational Source 
Eq_ Integer Source 
Eq_ Rational Source 
QuotientField Double Integer Source 
QuotientField Float Integer Source 
QuotientField Rational Int Source 
QuotientField Rational Integer Source 
KnownNat n => Reifies Nat n Integer 
KnownNat n => Quotient Nat Integer n Source 
KnownNat n => FiniteType (Z n) Source 
type Unsigned Integer = Integer 
type Signed Integer = Integer 
type Index Integer = Int Source 
type Index Integer = Int Source 
type Index Rational = Int Source 
type Index Rational = Int Source 
type Elem Integer = Integer Source 
type Elem Integer = Integer Source 
type Elem Rational = Rational Source 
type Elem Rational = Rational Source 
type Scalar Integer = Integer Source 
type Scalar Rational = Rational Source 
type Actor Integer = Integer Source 
type Actor Rational = Rational Source 
type Logic Integer = Bool Source 
type Logic Rational = Bool Source 
data Mutable m Integer = Mutable_ConT_GHC_Integer_Type_Integer (PrimRef m Integer) Source 
data Mutable m Rational = Mutable_ConT_GHC_Real_Rational (PrimRef m Rational) Source 
type ValidElem Integer e = () 
type ValidElem Rational e = () 
type SetIndex Integer a = Int Source 
type SetIndex Rational a = Int Source 
type SetElem Integer a = Integer Source 
type SetElem Rational a = Rational Source 
type (><) * * Integer Integer = Integer Source 
type (><) * * Rational Rational = Rational Source 
type (><) * * (Galois p k) Integer = Galois p k Source 
type Order (Z n) = n Source 

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.

Instances

Eq Float 
Floating Float 
Ord Float 
Read Float 
RealFloat Float 
Generic Float 
Arbitrary Float 
CoArbitrary Float 
Storable Float 
SerialEndian Float 
Serial Float 
FromField Float

Accepts same syntax as rational. Ignores whitespace.

ToField Float

Uses decimal notation or scientific notation, depending on the number.

NFData Float 
Erf Float 
InvErf Float 
IncGamma Float

This instance uses the Double instance.

Gamma Float 
Hashable Float 
Numeric Float 
Product Float 
Convert Float 
RealElement Float 
Element Float 
Prim Float 
Unbox Float 
Precise Float 
Lift Float 
IsMutable Float Source 
IxContainer Float Source 
CanError Float Source 
Metric Float Source 
TensorAlgebra Float Source 
Hilbert Float Source 
Banach Float Source 
VectorSpace Float Source 
FiniteModule Float Source 
FreeModule Float Source 
Module Float Source 
Normed Float Source 
Real Float Source 
ExpField Float Source 
ExpRing Float Source 
RationalField Float Source 
BoundedField Float Source 
OrdField Float Source 
Field Float Source 
Ring Float Source 
Rig Float Source 
Rg Float Source 
Abelian Float Source 
Group Float Source 
Cancellative Float Source 
Monoid Float Source 
Action Float Source 
Semigroup Float Source 
Bounded Float Source 
Ord_ Float Source 
Lattice_ Float Source 
MinBound_ Float Source 
POrd_ Float Source 
Eq_ Float Source 
IArray UArray Float 
Normed Vector Float 
Normed Matrix Float 
Precision Float Double 
Container Vector Float 
Vector Vector Float 
MVector MVector Float 
QuotientField Float Int Source 
QuotientField Float Integer Source 
Normed Vector (Complex Float) 
Normed Matrix (Complex Float) 
Container Vector (Complex Float) 
Gamma (Complex Float) 
Numeric (Complex Float) 
Product (Complex Float) 
Convert (Complex Float) 
Element (Complex Float) 
MArray (STUArray s) Float (ST s) 
Precision (Complex Float) (Complex Double) 
type Rep Float = D1 D_Float (C1 C_Float (S1 NoSelector (Rec0 Float))) 
type RealOf Float = Float 
type ComplexOf Float = Complex Float 
type SingleOf Float = Float 
type DoubleOf Float = Double 
data Vector Float = V_Float (Vector Float) 
type Index Float = Int Source 
type Index Float = Int Source 
type Elem Float = Float Source 
type Elem Float = Float Source 
type Scalar Float = Float Source 
type Actor Float = Float Source 
type Logic Float = Bool Source 
data MVector s Float = MV_Float (MVector s Float) 
data Mutable m Float = Mutable_ConT_GHC_Types_Float (PrimRef m Float) Source 
type ValidElem Float e = () 
type SetIndex Float a = Int Source 
type SetElem Float a = Float Source 
type (><) * * Float Float = Float Source 
type RealOf (Complex Float) = Float 
type ComplexOf (Complex Float) = Complex Float 

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.

Instances

Eq Double 
Floating Double 
Ord Double 
Read Double 
RealFloat Double 
Generic Double 
Arbitrary Double 
CoArbitrary Double 
Storable Double 
SerialEndian Double 
Serial Double 
FromField Double

Accepts same syntax as rational. Ignores whitespace.

ToField Double

Uses decimal notation or scientific notation, depending on the number.

NFData Double 
Erf Double 
InvErf Double 
IncGamma Double

I have not yet come up with a good strategy for evaluating these functions for negative x. They can be rather numerically unstable.

Gamma Double 
Hashable Double 
Numeric Double 
Field Double 
Product Double 
Convert Double 
RealElement Double 
Element Double 
Prim Double 
Unbox Double 
Precise Double 
Lift Double 
IsMutable Double Source 
IxContainer Double Source 
CanError Double Source 
Metric Double Source 
TensorAlgebra Double Source 
Hilbert Double Source 
Banach Double Source 
VectorSpace Double Source 
FiniteModule Double Source 
FreeModule Double Source 
Module Double Source 
Normed Double Source 
Real Double Source 
ExpField Double Source 
ExpRing Double Source 
RationalField Double Source 
BoundedField Double Source 
OrdField Double Source 
Field Double Source 
Ring Double Source 
Rig Double Source 
Rg Double Source 
Abelian Double Source 
Group Double Source 
Cancellative Double Source 
Monoid Double Source 
Action Double Source 
Semigroup Double Source 
Bounded Double Source 
Ord_ Double Source 
Lattice_ Double Source 
MinBound_ Double Source 
POrd_ Double Source 
Eq_ Double Source 
IArray UArray Double 
Normed Vector Double 
Normed Matrix Double 
Precision Float Double 
Container Vector Double 
Vector Vector Double 
MVector MVector Double 
QuotientField Double Int Source 
QuotientField Double Integer Source 
Normed Vector (Complex Double) 
Normed Matrix (Complex Double) 
Container Vector (Complex Double) 
Gamma (Complex Double) 
Numeric (Complex Double) 
Field (Complex Double) 
Product (Complex Double) 
Convert (Complex Double) 
Element (Complex Double) 
MArray (STUArray s) Double (ST s) 
Precision (Complex Float) (Complex Double) 
type Rep Double = D1 D_Double (C1 C_Double (S1 NoSelector (Rec0 Double))) 
type RealOf Double = Double 
type ComplexOf Double = Complex Double 
type SingleOf Double = Float 
type DoubleOf Double = Double 
data Vector Double = V_Double (Vector Double) 
type Index Double = Int Source 
type Index Double = Int Source 
type Elem Double = Double Source 
type Elem Double = Double Source 
type Scalar Double = Double Source 
type Actor Double = Double Source 
type Logic Double = Bool Source 
data MVector s Double = MV_Double (MVector s Double) 
data Mutable m Double = Mutable_ConT_GHC_Types_Double (PrimRef m Double) Source 
type ValidElem Double e = () 
type SetIndex Double a = Int Source 
type SetElem Double a = Double Source 
type (><) * * Double Double = Double Source 
type RealOf (Complex Double) = Double 
type ComplexOf (Complex Double) = Complex Double 

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 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 ST s a :: * -> * -> *

The strict state-transformer monad. A computation of type ST s a transforms an internal state indexed by s, and returns a value of type a. The s parameter is either

  • an uninstantiated type variable (inside invocations of runST), or
  • RealWorld (inside invocations of stToIO).

It serves to keep the internal states of different invocations of runST separate from each other and from invocations of stToIO.

The >>= and >> operations are strict in the state (though not in values stored in the state). For example,

runST (writeSTRef _|_ v >>= f) = _|_

Instances

Monad (ST s) 
Functor (ST s) 
Applicative (ST s) 
PrimMonad (ST s) 
PrimBase (ST s) 
MArray (STUArray s) Word (ST s) 
MArray (STUArray s) Word8 (ST s) 
MArray (STUArray s) Word64 (ST s) 
MArray (STUArray s) Word32 (ST s) 
MArray (STUArray s) Word16 (ST s) 
MArray (STUArray s) Int (ST s) 
MArray (STUArray s) Int8 (ST s) 
MArray (STUArray s) Int64 (ST s) 
MArray (STUArray s) Int32 (ST s) 
MArray (STUArray s) Int16 (ST s) 
MArray (STUArray s) Float (ST s) 
MArray (STUArray s) Double (ST s) 
MArray (STUArray s) Char (ST s) 
MArray (STUArray s) Bool (ST s) 
MArray (STArray s) e (ST s) 
MArray (STUArray s) (StablePtr a) (ST s) 
MArray (STUArray s) (Ptr a) (ST s) 
MArray (STUArray s) (FunPtr a) (ST s) 
Show (ST s a) 
type PrimState (ST s) = s 

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 
Serial1 Maybe 
Apply Maybe 
Bind Maybe 
Eq1 Maybe 
Ord1 Maybe 
Read1 Maybe 
Show1 Maybe 
Eq a => Eq (Maybe a) 
Ord a => Ord (Maybe a) 
Read a => Read (Maybe a) 
Show a => Show (Maybe a) 
Generic (Maybe a) 
Arbitrary a => Arbitrary (Maybe a) 
CoArbitrary a => CoArbitrary (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.

Serial a => Serial (Maybe a) 
FromField a => FromField (Maybe a)

Nothing if the Field is empty, Just otherwise.

ToField a => ToField (Maybe a)

Nothing is encoded as an empty field.

NFData a => NFData (Maybe a) 
Hashable a => Hashable (Maybe a) 
Semigroup a => Semigroup (Maybe a) 
Ixed (Maybe a) 
At (Maybe a) 
Lift a => Lift (Maybe a) 
CanError (Maybe a) Source 
Semigroup a => Monoid (Maybe a) Source 
Semigroup a => Semigroup (Maybe a) Source 
ValidEq a => Eq_ (Maybe a) Source 
type Rep1 Maybe = D1 D1Maybe ((:+:) (C1 C1_0Maybe U1) (C1 C1_1Maybe (S1 NoSelector Par1))) 
data Mutable m (Maybe a0) = Mutable_AppT__ConT_GHC_Base_Maybe___VarT_a_1627508563_ (PrimRef m (Maybe a)) Source 
type Rep (Maybe a) = D1 D1Maybe ((:+:) (C1 C1_0Maybe U1) (C1 C1_1Maybe (S1 NoSelector (Rec0 a)))) 
type Index (Maybe a) = () 
type IxValue (Maybe a) = a 
type Scalar (Maybe a) = Scalar a Source 
type Logic (Maybe a) = Logic a Source 
type (==) (Maybe k) a b = EqMaybe k a b 

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

Serial2 Either 
Monad (Either e) 
Functor (Either a) 
Applicative (Either e) 
Foldable (Either a) 
Traversable (Either a) 
Generic1 (Either a) 
Serial a => Serial1 (Either a) 
Apply (Either a) 
Bind (Either a) 
Eq a => Eq1 (Either a) 
Ord a => Ord1 (Either a) 
Read a => Read1 (Either a) 
Show a => Show1 (Either a) 
(Eq a, Eq b) => Eq (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) 
(Arbitrary a, Arbitrary b) => Arbitrary (Either a b) 
(CoArbitrary a, CoArbitrary b) => CoArbitrary (Either a b) 
(Serial a, Serial b) => Serial (Either a b) 
FromField a => FromField (Either Field a)

Left field if conversion failed, Right otherwise.

(NFData a, NFData b) => NFData (Either a b) 
(Hashable a, Hashable b) => Hashable (Either a b) 
Semigroup (Either a b) 
(Lift a, Lift b) => Lift (Either a b) 
data Mutable m (Either a0 b0) = Mutable_AppT__AppT__ConT_Data_Either_Either___VarT_a_1627701788____VarT_b_1627701789_ (PrimRef m (Either a b)) Source 
type Rep1 (Either a) = D1 D1Either ((:+:) (C1 C1_0Either (S1 NoSelector (Rec0 a))) (C1 C1_1Either (S1 NoSelector Par1))) 
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 

Prelude functions

build :: (forall b. (a -> b -> b) -> b -> b) -> [a]

A list producer that can be fused with foldr. This function is merely

   build g = g (:) []

but GHC's simplifier will transform an expression of the form foldr k z (build g), which may arise after inlining, to g k z, which avoids producing an intermediate list.

(++) :: [a] -> [a] -> [a] infixr 5

Append two lists, i.e.,

[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
[x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]

If the first list is not finite, the result is the first list.

all :: Foldable t => (a -> Bool) -> t a -> Bool

Determines whether all elements of the structure satisfy the predicate.

map :: (a -> b) -> [a] -> [b]

map f xs is the list obtained by applying f to each element of xs, i.e.,

map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
map f [x1, x2, ...] == [f x1, f x2, ...]

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.

otherwise :: Bool

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

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

error :: [Char] -> a

error stops execution and displays an error message.

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.

subhask functions

assert :: String -> Bool -> a -> a Source

FIXME: Move to a better spot Add rewrite rules to remove with optimization -O

ifThenElse :: Bool -> t -> t -> t Source

Modules

module Data.Proxy

Non-base types

class Arbitrary a where

Random generation and shrinking of values.

Minimal complete definition

Nothing

Methods

arbitrary :: Gen a

A generator for values of the given type.

shrink :: a -> [a]

Produces a (possibly) empty list of all the possible immediate shrinks of the given value. The default implementation returns the empty list, so will not try to shrink the value.

Most implementations of shrink should try at least three things:

  1. Shrink a term to any of its immediate subterms.
  2. Recursively apply shrink to all immediate subterms.
  3. Type-specific shrinkings such as replacing a constructor by a simpler constructor.

For example, suppose we have the following implementation of binary trees:

data Tree a = Nil | Branch a (Tree a) (Tree a)

We can then define shrink as follows:

shrink Nil = []
shrink (Branch x l r) =
  -- shrink Branch to Nil
  [Nil] ++
  -- shrink to subterms
  [l, r] ++
  -- recursively shrink subterms
  [Branch x' l' r' | (x', l', r') <- shrink (x, l, r)]

There are a couple of subtleties here:

  • QuickCheck tries the shrinking candidates in the order they appear in the list, so we put more aggressive shrinking steps (such as replacing the whole tree by Nil) before smaller ones (such as recursively shrinking the subtrees).
  • It is tempting to write the last line as [Branch x' l' r' | x' <- shrink x, l' <- shrink l, r' <- shrink r] but this is the wrong thing! It will force QuickCheck to shrink x, l and r in tandem, and shrinking will stop once one of the three is fully shrunk.

There is a fair bit of boilerplate in the code above. We can avoid it with the help of some generic functions; note that these only work on GHC 7.2 and above. The function genericShrink tries shrinking a term to all of its subterms and, failing that, recursively shrinks the subterms. Using it, we can define shrink as:

shrink x = shrinkToNil x ++ genericShrink x
  where
    shrinkToNil Nil = []
    shrinkToNil (Branch _ l r) = [Nil]

genericShrink is a combination of subterms, which shrinks a term to any of its subterms, and recursivelyShrink, which shrinks all subterms of a term. These may be useful if you need a bit more control over shrinking than genericShrink gives you.

A final gotcha: we cannot define shrink as simply shrink x = Nil:genericShrink x as this shrinks Nil to Nil, and shrinking will go into an infinite loop.

If all this leaves you bewildered, you might try shrink = genericShrink to begin with, after deriving Generic for your type. However, if your data type has any special invariants, you will need to check that genericShrink can't break those invariants.

Instances

Arbitrary Bool 
Arbitrary Char 
Arbitrary Double 
Arbitrary Float 
Arbitrary Int 
Arbitrary Int8 
Arbitrary Int16 
Arbitrary Int32 
Arbitrary Int64 
Arbitrary Integer 
Arbitrary Ordering 
Arbitrary Word 
Arbitrary Word8 
Arbitrary Word16 
Arbitrary Word32 
Arbitrary Word64 
Arbitrary () 
Arbitrary Natural 
Arbitrary POrdering 
Arbitrary K3 
Arbitrary H3 
Arbitrary a => Arbitrary [a] 
(Integral a, Arbitrary a) => Arbitrary (Ratio a) 
Arbitrary a => Arbitrary (Maybe a) 
HasResolution a => Arbitrary (Fixed a) 
(RealFloat a, Arbitrary a) => Arbitrary (Complex a) 
Arbitrary a0 => Arbitrary (WithPreludeOrd a) 
Arbitrary t0 => Arbitrary (NonNegative t) 
Arbitrary (Z n0) => Arbitrary (VedicSquare n) 
(Arbitrary v, Arbitrary (Scalar v), HasScalar v) => Arbitrary (Ball v) 
Arbitrary (Z (Order a0)) => Arbitrary (ZIndex a) 
Arbitrary e => Arbitrary (BArray e) 
(Unboxable e, Arbitrary e) => Arbitrary (UArray e) 
(Lattice v, Arbitrary v) => Arbitrary (Box v) 
Arbitrary a0 => Arbitrary (Jaccard a) 
Arbitrary a0 => Arbitrary (Hamming a) 
Arbitrary a0 => Arbitrary (Levenshtein a) 
Arbitrary s0 => Arbitrary (Uncompensated s) 
Arbitrary a0 => Arbitrary (Lexical a) 
Arbitrary a0 => Arbitrary (ComponentWise a) 
(OrdRing_ r, Arbitrary r) => Arbitrary (Goedel_ r) 
Arbitrary b0 => Arbitrary (Boolean2Ring b) 
(Eq a, Arbitrary a) => Arbitrary (Seq a) 
(Eq e, Semigroup e, Arbitrary e) => Arbitrary (IntMap e) 
(Eq e, Semigroup e, Arbitrary e) => Arbitrary (IntMap' e) 
(Ord a, Arbitrary a) => Arbitrary (Set a) 
Arbitrary (ByteString Char) 
Arbitrary a0 => Arbitrary (PartitionOnNewline a) 
(CoArbitrary a, Arbitrary b) => Arbitrary (a -> b) 
(Arbitrary a, Arbitrary b) => Arbitrary (Either a b) 
(Arbitrary a, Arbitrary b) => Arbitrary (a, b) 
(IsMutable a, PrimBase m, Arbitrary a) => Arbitrary (Mutable m a) 
(Arbitrary x, Arbitrary y) => Arbitrary (Labeled' x y) 
Arbitrary (Z ((^) p0 k0)) => Arbitrary (Galois p k) 
(Eq e, Ord i, Semigroup e, Arbitrary i, Arbitrary e) => Arbitrary (Map i e) 
(Eq e, Ord i, Semigroup e, Arbitrary i, Arbitrary e) => Arbitrary (Map' i e) 
(Arbitrary a, Arbitrary b, Arbitrary c) => Arbitrary (a, b, c) 
(Quotient k a b, Arbitrary a) => Arbitrary ((/) k a b) 
(KnownNat n, Arbitrary r, ValidSVector Nat n r, FreeModule r, IsScalar r) => Arbitrary (SVector Nat n r) 
(Arbitrary r, ValidSVector Symbol n r, FreeModule r, IsScalar r) => Arbitrary (SVector Symbol n r) 
(Arbitrary r, Prim r, FreeModule r, IsScalar r) => Arbitrary (UVector Symbol n r) 
(Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) => Arbitrary (a, b, c, d) 
(Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e) => Arbitrary (a, b, c, d, e)