License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Foundation
Contents
Description
I tried to picture clusters of information As they moved through the computer What do they look like?
Alternative Prelude
- ($) :: (a -> b) -> a -> b
- ($!) :: (a -> b) -> a -> b
- (&&) :: Bool -> Bool -> Bool
- (||) :: Bool -> Bool -> Bool
- (.) :: Category k cat => forall (b :: k) (c :: k) (a :: k). cat b c -> cat a b -> cat a c
- not :: Bool -> Bool
- otherwise :: Bool
- data Tuple2 a b = Tuple2 !a !b
- data Tuple3 a b c = Tuple3 !a !b !c
- data Tuple4 a b c d = Tuple4 !a !b !c !d
- class Fstable a where
- type ProductFirst a
- class Sndable a where
- type ProductSecond a
- class Thdable a where
- type ProductThird a
- id :: Category k cat => forall (a :: k). cat a a
- maybe :: b -> (a -> b) -> Maybe a -> b
- either :: (a -> c) -> (b -> c) -> Either a b -> c
- flip :: (a -> b -> c) -> b -> a -> c
- const :: a -> b -> a
- error :: HasCallStack => String -> a
- putStr :: String -> IO ()
- putStrLn :: String -> IO ()
- getArgs :: IO [String]
- uncurry :: (a -> b -> c) -> (a, b) -> c
- curry :: ((a, b) -> c) -> a -> b -> c
- swap :: (a, b) -> (b, a)
- until :: (a -> Bool) -> (a -> a) -> a -> a
- asTypeOf :: a -> a -> a
- undefined :: HasCallStack => a
- seq :: a -> b -> b
- class NormalForm a
- deepseq :: NormalForm a => a -> b -> b
- force :: NormalForm a => a -> a
- class Show a
- show :: Show a => a -> String
- class Eq a => Ord a where
- class Eq a where
- class Bounded a where
- class Enum a where
- class Functor (f :: * -> *) where
- class Integral a where
- class Fractional a where
- class HasNegation a where
- class Bifunctor (p :: * -> * -> *) where
- class Functor f => Applicative (f :: * -> *) where
- class Applicative m => Monad (m :: * -> *) where
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- class IsString a where
- class IsList l where
- class (Enum a, Eq a, Ord a, Integral a) => IsIntegral a where
- class (Enum a, Eq a, Ord a, Integral a, IsIntegral a) => IsNatural a where
- class Signed a where
- class Additive a where
- class Subtractive a where
- type Difference a :: *
- class Multiplicative a where
- class (Additive a, Multiplicative a) => IDivisible a where
- class Multiplicative a => Divisible a where
- data Maybe a :: * -> *
- data Ordering :: *
- data Bool :: *
- data Char :: *
- data Char7 :: *
- data IO a :: * -> *
- data Either a b :: * -> * -> *
- data Int8 :: *
- data Int16 :: *
- data Int32 :: *
- data Int64 :: *
- data Word8 :: *
- data Word16 :: *
- data Word32 :: *
- data Word64 :: *
- data Word :: *
- data Word128 :: *
- data Word256 :: *
- data Int :: *
- data Integer :: *
- data Natural :: *
- type Rational = Ratio Integer
- data Float :: *
- data Double :: *
- newtype CountOf ty :: * -> * = CountOf Int
- newtype Offset ty :: * -> * = Offset Int
- toCount :: Int -> CountOf ty
- fromCount :: CountOf ty -> Int
- data UArray ty :: * -> *
- class Eq ty => PrimType ty
- data Array a :: * -> *
- data String :: *
- (^^) :: (Fractional a, Integral b) => a -> b -> a
- fromIntegral :: (Integral a, Num b) => a -> b
- realToFrac :: (Real a, Fractional b) => a -> b
- class Semigroup a
- class Monoid a where
- (<>) :: Monoid m => m -> m -> m
- class (IsList c, Item c ~ Element c) => Collection c where
- and :: (Collection col, Element col ~ Bool) => col -> Bool
- or :: (Collection col, Element col ~ Bool) => col -> Bool
- class (IsList c, Item c ~ Element c, Monoid c, Collection c) => Sequential c where
- data NonEmpty a :: * -> *
- nonEmpty :: Collection c => c -> Maybe (NonEmpty c)
- class Foldable collection where
- mapMaybe :: (a -> Maybe b) -> [a] -> [b]
- catMaybes :: [Maybe a] -> [a]
- fromMaybe :: a -> Maybe a -> a
- isJust :: Maybe a -> Bool
- isNothing :: Maybe a -> Bool
- listToMaybe :: [a] -> Maybe a
- maybeToList :: Maybe a -> [a]
- partitionEithers :: [Either a b] -> ([a], [b])
- lefts :: [Either a b] -> [a]
- rights :: [Either a b] -> [b]
- on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (<|>) :: Alternative f => forall a. f a -> f a -> f a
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- class (Typeable * e, Show e) => Exception e where
- class Typeable k (a :: k)
- data SomeException :: *
- data IOException :: *
- data Proxy k (t :: k) :: forall k. k -> * = Proxy
- asProxyTypeOf :: a -> proxy a -> a
- data Partial a
- partial :: a -> Partial a
- data PartialError
- fromPartial :: Partial a -> a
- ifThenElse :: Bool -> a -> a -> a
- type LString = String
Standard
Operators
($) :: (a -> b) -> a -> b infixr 0 #
Application operator. This operator is redundant, since ordinary
application (f x)
means the same as (f
. However, $
x)$
has
low, right-associative binding precedence, so it sometimes allows
parentheses to be omitted; for example:
f $ g $ h x = f (g (h x))
It is also useful in higher-order situations, such as
,
or map
($
0) xs
.zipWith
($
) fs xs
($!) :: (a -> b) -> a -> b infixr 0 #
Strict (call-by-value) application operator. It takes a function and an argument, evaluates the argument to weak head normal form (WHNF), then calls the function with that value.
(.) :: Category k cat => forall (b :: k) (c :: k) (a :: k). cat b c -> cat a b -> cat a c infixr 9 #
morphism composition
Functions
Strict tuple (a,b)
Constructors
Tuple2 !a !b |
Instances
Bifunctor Tuple2 Source # | |
Nthable 1 (Tuple2 a b) Source # | |
Nthable 2 (Tuple2 a b) Source # | |
(Eq b, Eq a) => Eq (Tuple2 a b) Source # | |
(Data b, Data a) => Data (Tuple2 a b) Source # | |
(Ord b, Ord a) => Ord (Tuple2 a b) Source # | |
(Show b, Show a) => Show (Tuple2 a b) Source # | |
Generic (Tuple2 a b) Source # | |
(NormalForm a, NormalForm b) => NormalForm (Tuple2 a b) Source # | |
Sndable (Tuple2 a b) Source # | |
Fstable (Tuple2 a b) Source # | |
(Hashable a, Hashable b) => Hashable (Tuple2 a b) Source # | |
type NthTy 1 (Tuple2 a b) Source # | |
type NthTy 2 (Tuple2 a b) Source # | |
type Rep (Tuple2 a b) Source # | |
type ProductSecond (Tuple2 a b) Source # | |
type ProductFirst (Tuple2 a b) Source # | |
Strict tuple (a,b,c)
Constructors
Tuple3 !a !b !c |
Instances
Nthable 1 (Tuple3 a b c) Source # | |
Nthable 2 (Tuple3 a b c) Source # | |
Nthable 3 (Tuple3 a b c) Source # | |
(Eq c, Eq b, Eq a) => Eq (Tuple3 a b c) Source # | |
(Data c, Data b, Data a) => Data (Tuple3 a b c) Source # | |
(Ord c, Ord b, Ord a) => Ord (Tuple3 a b c) Source # | |
(Show c, Show b, Show a) => Show (Tuple3 a b c) Source # | |
Generic (Tuple3 a b c) Source # | |
(NormalForm a, NormalForm b, NormalForm c) => NormalForm (Tuple3 a b c) Source # | |
Thdable (Tuple3 a b c) Source # | |
Sndable (Tuple3 a b c) Source # | |
Fstable (Tuple3 a b c) Source # | |
(Hashable a, Hashable b, Hashable c) => Hashable (Tuple3 a b c) Source # | |
type NthTy 1 (Tuple3 a b c) Source # | |
type NthTy 2 (Tuple3 a b c) Source # | |
type NthTy 3 (Tuple3 a b c) Source # | |
type Rep (Tuple3 a b c) Source # | |
type ProductThird (Tuple3 a b c) Source # | |
type ProductSecond (Tuple3 a b c) Source # | |
type ProductFirst (Tuple3 a b c) Source # | |
Strict tuple (a,b,c,d)
Constructors
Tuple4 !a !b !c !d |
Instances
class Fstable a where Source #
Class of product types that have a first element
Minimal complete definition
Associated Types
type ProductFirst a Source #
Methods
fst :: a -> ProductFirst a Source #
class Sndable a where Source #
Class of product types that have a second element
Minimal complete definition
Associated Types
type ProductSecond a Source #
Methods
snd :: a -> ProductSecond a Source #
class Thdable a where Source #
Class of product types that have a third element
Minimal complete definition
Associated Types
type ProductThird a Source #
Methods
thd :: a -> ProductThird a Source #
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
, apply the first function to Left
aa
;
if it is
, apply the second function to Right
bb
.
Examples
We create two values of type
, one using the
Either
String
Int
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 #
takes its (first) two arguments in the reverse order of flip
ff
.
const x
is a unary function which evaluates to x
for all inputs.
For instance,
>>>
map (const 42) [0..3]
[42,42,42,42]
error :: HasCallStack => String -> a #
stop execution and displays an error message
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.
until :: (a -> Bool) -> (a -> a) -> a -> a #
yields the result of applying until
p ff
until p
holds.
undefined :: HasCallStack => a #
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
Instances
deepseq :: NormalForm a => a -> b -> b #
force :: NormalForm a => a -> a #
Type classes
Conversion of values to readable String
s.
Derived instances of Show
have the following properties, which
are compatible with derived instances of Read
:
- The result of
show
is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used. - If the constructor is defined to be an infix operator, then
showsPrec
will produce infix applications of the constructor. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
x
is less thand
(associativity is ignored). Thus, ifd
is0
then the result is never surrounded in parentheses; ifd
is11
it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then
show
will produce the record-syntax form, with the fields given in the same order as the original declaration.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Show
is equivalent to
instance (Show a) => Show (Tree a) where showsPrec d (Leaf m) = showParen (d > app_prec) $ showString "Leaf " . showsPrec (app_prec+1) m where app_prec = 10 showsPrec d (u :^: v) = showParen (d > up_prec) $ showsPrec (up_prec+1) u . showString " :^: " . showsPrec (up_prec+1) v where up_prec = 5
Note that right-associativity of :^:
is ignored. For example,
produces the stringshow
(Leaf 1 :^: Leaf 2 :^: Leaf 3)"Leaf 1 :^: (Leaf 2 :^: Leaf 3)"
.
Instances
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.
The Ord
class is used for totally ordered datatypes.
Instances of Ord
can be derived for any user-defined
datatype whose constituent types are in Ord
. The declared order
of the constructors in the data declaration determines the ordering
in derived Ord
instances. The Ordering
datatype allows a single
comparison to determine the precise ordering of two objects.
Minimal complete definition: either compare
or <=
.
Using compare
can be more efficient for complex types.
Methods
compare :: a -> a -> Ordering #
(<) :: a -> a -> Bool infix 4 #
(<=) :: a -> a -> Bool infix 4 #
(>) :: a -> a -> Bool infix 4 #
Instances
Ord Bool | |
Ord Char | |
Ord Double | |
Ord Float | |
Ord Int | |
Ord Int8 | Since: 2.1 |
Ord Int16 | Since: 2.1 |
Ord Int32 | Since: 2.1 |
Ord Int64 | Since: 2.1 |
Ord Integer | |
Ord Natural | |
Ord Ordering | |
Ord Word | |
Ord Word8 | Since: 2.1 |
Ord Word16 | Since: 2.1 |
Ord Word32 | Since: 2.1 |
Ord Word64 | Since: 2.1 |
Ord SomeTypeRep | |
Ord () | |
Ord TyCon | |
Ord BigNat | |
Ord Void | Since: 4.8.0.0 |
Ord Version | Since: 2.1 |
Ord ThreadId | Since: 4.2.0.0 |
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 CBlkSize | |
Ord CBlkCnt | |
Ord CClockId | |
Ord CFsBlkCnt | |
Ord CFsFilCnt | |
Ord CId | |
Ord CKey | |
Ord CTimer | |
Ord Fd | |
Ord AsyncException | |
Ord ArrayException | |
Ord ExitCode | |
Ord BufferMode | |
Ord Newline | |
Ord NewlineMode | |
Ord SeekMode | |
Ord ErrorCall | |
Ord ArithException | |
Ord All | |
Ord Any | |
Ord Fixity | |
Ord Associativity | |
Ord SourceUnpackedness | |
Ord SourceStrictness | |
Ord DecidedStrictness | |
Ord SomeSymbol | Since: 4.7.0.0 |
Ord SomeNat | Since: 4.7.0.0 |
Ord CChar | |
Ord CSChar | |
Ord CUChar | |
Ord CShort | |
Ord CUShort | |
Ord CInt | |
Ord CUInt | |
Ord CLong | |
Ord CULong | |
Ord CLLong | |
Ord CULLong | |
Ord CBool | |
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 WordPtr | |
Ord IntPtr | |
Ord IOMode | |
Ord GeneralCategory | |
Ord UTF32_Invalid | |
Ord Encoding | |
Ord String | |
Ord AsciiString | |
Ord Addr | |
Ord FileSize | |
Ord Word256 | |
Ord Word128 | |
Ord Char7 | |
Ord Bitmap # | |
Ord Arch # | |
Ord OS # | |
Ord Seconds # | |
Ord NanoSeconds # | |
Ord IPv6 # | |
Ord IPv4 # | |
Ord UUID # | |
Ord FilePath # | |
Ord a => Ord [a] | |
Ord a => Ord (Maybe a) | |
Integral a => Ord (Ratio a) | Since: 2.0.1 |
Ord (Ptr a) | |
Ord (FunPtr a) | |
Ord p => Ord (Par1 p) | |
Ord a => Ord (Min a) | |
Ord a => Ord (Max a) | |
Ord a => Ord (First a) | |
Ord a => Ord (Last a) | |
Ord m => Ord (WrappedMonoid m) | |
Ord a => Ord (Option a) | |
Ord a => Ord (NonEmpty a) | |
Ord a => Ord (ZipList a) | |
Ord a => Ord (Identity a) | |
Ord (ForeignPtr a) | Since: 2.1 |
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 (Array a) | |
(PrimType ty, Ord ty) => Ord (UArray ty) | |
(PrimType ty, Ord ty) => Ord (Block ty) | |
Ord (Offset ty) | |
Ord (CountOf ty) | |
Ord (Zn64 n) | |
Ord (Zn n) | |
Ord (FinalPtr a) | |
(ByteSwap a, Ord a) => Ord (LE a) | |
(ByteSwap a, Ord a) => Ord (BE a) | |
Ord a => Ord (DList a) # | |
(Ord ty, PrimType ty) => Ord (ChunkedUArray ty) # | |
(Ord b, Ord a) => Ord (Either a b) | |
Ord (V1 k p) | |
Ord (U1 k p) | Since: 4.9.0.0 |
Ord (TypeRep k a) | Since: 4.4.0.0 |
(Ord a, Ord b) => Ord (a, b) | |
(Ix i, Ord e) => Ord (Array i e) | Since: 2.1 |
Ord a => Ord (Arg a b) | Since: 4.9.0.0 |
Ord (Proxy k s) | Since: 4.7.0.0 |
Ord a => Ord (ListN n a) | |
(Ord b, Ord a) => Ord (These a b) | |
(Ord b, Ord a) => Ord (Tuple2 a b) # | |
Ord (f p) => Ord (Rec1 k f p) | |
Ord (URec k (Ptr ()) p) | |
Ord (URec k Char p) | |
Ord (URec k Double p) | |
Ord (URec k Float p) | |
Ord (URec k Int p) | |
Ord (URec k Word p) | |
(Ord a, Ord b, Ord c) => Ord (a, b, c) | |
Ord a => Ord (Const k a b) | |
Ord (f a) => Ord (Alt k f a) | |
Ord (Coercion k a b) | |
Ord ((:~:) k a b) | |
(Ord c, Ord b, Ord a) => Ord (Tuple3 a b c) # | |
Ord c => Ord (K1 k i c p) | |
(Ord (g p), Ord (f p)) => Ord ((:+:) k f g p) | |
(Ord (g p), Ord (f p)) => Ord ((:*:) k f g p) | |
(Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d) | |
Ord ((:~~:) k1 k2 a b) | Since: 4.10.0.0 |
(Ord d, Ord c, Ord b, Ord a) => Ord (Tuple4 a b c d) # | |
Ord (f p) => Ord (M1 k i c f p) | |
Ord (f (g p)) => Ord ((:.:) k2 k1 f g p) | |
(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) | |
The Eq
class defines equality (==
) and inequality (/=
).
All the basic datatypes exported by the Prelude are instances of Eq
,
and Eq
may be derived for any datatype whose constituents are also
instances of Eq
.
Instances
Eq Bool | |
Eq Char | |
Eq Double | |
Eq Float | |
Eq Int | |
Eq Int8 | Since: 2.1 |
Eq Int16 | Since: 2.1 |
Eq Int32 | Since: 2.1 |
Eq Int64 | Since: 2.1 |
Eq Integer | |
Eq Natural | |
Eq Ordering | |
Eq Word | |
Eq Word8 | Since: 2.1 |
Eq Word16 | Since: 2.1 |
Eq Word32 | Since: 2.1 |
Eq Word64 | Since: 2.1 |
Eq SomeTypeRep | |
Eq () | |
Eq TyCon | |
Eq Module | |
Eq TrName | |
Eq EventLifetime | |
Eq BigNat | |
Eq Void | Since: 4.8.0.0 |
Eq SpecConstrAnnotation | |
Eq Constr | Equality of constructors Since: 4.0.0.0 |
Eq DataRep | |
Eq ConstrRep | |
Eq Fixity | |
Eq Version | Since: 2.1 |
Eq HandlePosn | Since: 4.1.0.0 |
Eq ThreadId | Since: 4.2.0.0 |
Eq BlockReason | |
Eq ThreadStatus | |
Eq Event | |
Eq Lifetime | |
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 CBlkSize | |
Eq CBlkCnt | |
Eq CClockId | |
Eq CFsBlkCnt | |
Eq CFsFilCnt | |
Eq CId | |
Eq CKey | |
Eq CTimer | |
Eq Fd | |
Eq Errno | Since: 2.1 |
Eq AsyncException | |
Eq ArrayException | |
Eq ExitCode | |
Eq IOErrorType | Since: 4.1.0.0 |
Eq Handle | Since: 4.1.0.0 |
Eq BufferMode | |
Eq Newline | |
Eq NewlineMode | |
Eq IODeviceType | |
Eq SeekMode | |
Eq MaskingState | |
Eq IOException | Since: 4.1.0.0 |
Eq ErrorCall | |
Eq ArithException | |
Eq All | |
Eq Any | |
Eq Fixity | |
Eq Associativity | |
Eq SourceUnpackedness | |
Eq SourceStrictness | |
Eq DecidedStrictness | |
Eq SomeSymbol | Since: 4.7.0.0 |
Eq SomeNat | Since: 4.7.0.0 |
Eq CChar | |
Eq CSChar | |
Eq CUChar | |
Eq CShort | |
Eq CUShort | |
Eq CInt | |
Eq CUInt | |
Eq CLong | |
Eq CULong | |
Eq CLLong | |
Eq CULLong | |
Eq CBool | |
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 WordPtr | |
Eq IntPtr | |
Eq IOMode | |
Eq Lexeme | |
Eq Number | |
Eq GeneralCategory | |
Eq SrcLoc | |
Eq CM | |
Eq ASCII7_Invalid | |
Eq ISO_8859_1_Invalid | |
Eq UTF16_Invalid | |
Eq UTF32_Invalid | |
Eq Encoding | |
Eq String | |
Eq ValidationFailure | |
Eq AsciiString | |
Eq OutOfBoundOperation | |
Eq RecastSourceSize | |
Eq RecastDestinationSize | |
Eq Addr | |
Eq FileSize | |
Eq Word256 | |
Eq Word128 | |
Eq Char7 | |
Eq Endianness | |
Eq Sign # | |
Eq Bitmap # | |
Eq PartialError # | |
Eq And # | |
Eq Condition # | |
Eq Arch # | |
Eq OS # | |
Eq Seconds # | |
Eq NanoSeconds # | |
Eq IPv6 # | |
Eq IPv4 # | |
Eq UUID # | |
Eq FileName # | |
Eq FilePath # | |
Eq Relativity # | |
Eq a => Eq [a] | |
Eq a => Eq (Maybe a) | |
Eq a => Eq (Ratio a) | |
Eq (Ptr a) | |
Eq (FunPtr a) | |
Eq p => Eq (Par1 p) | |
Eq a => Eq (Min a) | |
Eq a => Eq (Max a) | |
Eq a => Eq (First a) | |
Eq a => Eq (Last a) | |
Eq m => Eq (WrappedMonoid m) | |
Eq a => Eq (Option a) | |
Eq a => Eq (NonEmpty a) | |
Eq a => Eq (ZipList a) | |
Eq a => Eq (Identity a) | |
Eq (TVar a) | Since: 4.8.0.0 |
Eq (ForeignPtr a) | Since: 2.1 |
Eq (IORef a) | Since: 4.1.0.0 |
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 (Array a) | |
(PrimType ty, Eq ty) => Eq (UArray ty) | |
(PrimType ty, Eq ty) => Eq (Block ty) | |
Eq a => Eq (NonEmpty a) | |
Eq (Offset ty) | |
Eq (CountOf ty) | |
Eq (Zn64 n) | |
Eq (Zn n) | |
Eq (FinalPtr a) | |
Eq a => Eq (LE a) | |
Eq a => Eq (BE a) | |
Eq a => Eq (DList a) # | |
PrimType ty => Eq (ChunkedUArray ty) # | |
(Eq b, Eq a) => Eq (Either a b) | |
Eq (V1 k p) | |
Eq (U1 k p) | Since: 4.9.0.0 |
Eq (TypeRep k a) | Since: 2.1 |
(Eq a, Eq b) => Eq (a, b) | |
(Ix i, Eq e) => Eq (Array i e) | Since: 2.1 |
Eq a => Eq (Arg a b) | Since: 4.9.0.0 |
Eq (Proxy k s) | Since: 4.7.0.0 |
Eq a => Eq (ListN n a) | |
(Eq b, Eq a) => Eq (These a b) | |
(Eq b, Eq a) => Eq (Tuple2 a b) # | |
Eq (f p) => Eq (Rec1 k f p) | |
Eq (URec k (Ptr ()) p) | |
Eq (URec k Char p) | |
Eq (URec k Double p) | |
Eq (URec k Float p) | |
Eq (URec k Int p) | |
Eq (URec k Word p) | |
(Eq a, Eq b, Eq c) => Eq (a, b, c) | |
Eq (STArray s i e) | Since: 2.1 |
Eq a => Eq (Const k a b) | |
Eq (f a) => Eq (Alt k f a) | |
Eq (Coercion k a b) | |
Eq ((:~:) k a b) | |
(Eq c, Eq b, Eq a) => Eq (Tuple3 a b c) # | |
Eq c => Eq (K1 k i c p) | |
(Eq (g p), Eq (f p)) => Eq ((:+:) k f g p) | |
(Eq (g p), Eq (f p)) => Eq ((:*:) k f g p) | |
(Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) | |
Eq ((:~~:) k1 k2 a b) | Since: 4.10.0.0 |
(Eq d, Eq c, Eq b, Eq a) => Eq (Tuple4 a b c d) # | |
Eq (f p) => Eq (M1 k i c f p) | |
Eq (f (g p)) => Eq ((:.:) k2 k1 f g p) | |
(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) | |
The Bounded
class is used to name the upper and lower limits of a
type. Ord
is not a superclass of Bounded
since types that are not
totally ordered may also have upper and lower bounds.
The Bounded
class may be derived for any enumeration type;
minBound
is the first constructor listed in the data
declaration
and maxBound
is the last.
Bounded
may also be derived for single-constructor datatypes whose
constituent types are in Bounded
.
Instances
Class Enum
defines operations on sequentially ordered types.
The enumFrom
... methods are used in Haskell's translation of
arithmetic sequences.
Instances of Enum
may be derived for any enumeration type (types
whose constructors have no fields). The nullary constructors are
assumed to be numbered left-to-right by fromEnum
from 0
through n-1
.
See Chapter 10 of the Haskell Report for more details.
For any type that is an instance of class Bounded
as well as Enum
,
the following should hold:
- The calls
andsucc
maxBound
should result in a runtime error.pred
minBound
fromEnum
andtoEnum
should give a runtime error if the result value is not representable in the result type. For example,
is an error.toEnum
7 ::Bool
enumFrom
andenumFromThen
should be defined with an implicit bound, thus:
enumFrom x = enumFromTo x maxBound enumFromThen x y = enumFromThenTo x y bound where bound | fromEnum y >= fromEnum x = maxBound | otherwise = minBound
Methods
the successor of a value. For numeric types, succ
adds 1.
the predecessor of a value. For numeric types, pred
subtracts 1.
Convert from an 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
.
Used in Haskell's translation of [n..]
.
enumFromThen :: a -> a -> [a] #
Used in Haskell's translation of [n,n'..]
.
enumFromTo :: a -> a -> [a] #
Used in Haskell's translation of [n..m]
.
enumFromThenTo :: a -> a -> a -> [a] #
Used in Haskell's translation of [n,n'..m]
.
Instances
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
Instances
Integral Literal support
e.g. 123 :: Integer 123 :: Word8
Minimal complete definition
Methods
fromInteger :: Integer -> a #
Instances
class Fractional a where #
Fractional Literal support
e.g. 1.2 :: Double 0.03 :: Float
Minimal complete definition
Methods
fromRational :: Rational -> a #
class HasNegation a where #
Negation support
e.g. -(f x)
Minimal complete definition
Instances
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
id
≡id
If you supply first
and second
, ensure:
first
id
≡id
second
id
≡id
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 ifirst
(f.
g) ≡first
f.
first
gsecond
(f.
g) ≡second
f.
second
g
Since: 4.8.0.0
Instances
Bifunctor Either | Since: 4.8.0.0 |
Bifunctor (,) | Since: 4.8.0.0 |
Bifunctor Arg | Since: 4.9.0.0 |
Bifunctor These | |
Bifunctor Tuple2 # | |
Bifunctor ((,,) x1) | Since: 4.8.0.0 |
Bifunctor (Const *) | Since: 4.8.0.0 |
Bifunctor (K1 * i) | Since: 4.9.0.0 |
Bifunctor ((,,,) x1 x2) | Since: 4.8.0.0 |
Bifunctor ((,,,,) x1 x2 x3) | Since: 4.8.0.0 |
Bifunctor ((,,,,,) x1 x2 x3 x4) | Since: 4.8.0.0 |
Bifunctor ((,,,,,,) x1 x2 x3 x4 x5) | Since: 4.8.0.0 |
class Functor f => Applicative (f :: * -> *) where #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*>
or liftA2
. If it defines both, then they must behave
the same as their default definitions:
(
<*>
) = liftA2
id
liftA2
f x y = f <$>
x <*>
y
Further, any definition must satisfy the following:
- 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
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2
p (liftA2
q u v) =liftA2
f u .liftA2
g v
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Methods
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
liftA2 :: (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
Some functors support an implementation of liftA2
that is more
efficient than the default one. In particular, if fmap
is an
expensive operation, it is likely better to use liftA2
than to
fmap
over the structure and then use <*>
.
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Instances
Applicative [] | Since: 2.1 |
Applicative Maybe | Since: 2.1 |
Applicative IO | Since: 2.1 |
Applicative Par1 | Since: 4.9.0.0 |
Applicative P | Since: 4.5.0.0 |
Applicative Min | Since: 4.9.0.0 |
Applicative Max | Since: 4.9.0.0 |
Applicative First | Since: 4.9.0.0 |
Applicative Last | Since: 4.9.0.0 |
Applicative Option | Since: 4.9.0.0 |
Applicative NonEmpty | Since: 4.9.0.0 |
Applicative ZipList | f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsN
|
Applicative Identity | Since: 4.8.0.0 |
Applicative STM | Since: 4.8.0.0 |
Applicative Dual | Since: 4.8.0.0 |
Applicative Sum | Since: 4.8.0.0 |
Applicative Product | Since: 4.8.0.0 |
Applicative First | |
Applicative Last | |
Applicative ReadP | Since: 4.6.0.0 |
Applicative DList # | |
Applicative Partial # | |
Applicative Gen # | |
Applicative Check # | |
Applicative (Either e) | Since: 3.0 |
Applicative (U1 *) | Since: 4.9.0.0 |
Monoid a => Applicative ((,) a) | For tuples, the ("hello ", (+15)) <*> ("world!", 2002) ("hello world!",2017) Since: 2.1 |
Monad m => Applicative (WrappedMonad m) | Since: 2.1 |
Arrow a => Applicative (ArrowMonad a) | Since: 4.6.0.0 |
Applicative (Proxy *) | Since: 4.7.0.0 |
Applicative (ST s) | Since: 4.4.0.0 |
Applicative m => Applicative (ResourceT m) # | |
ParserSource input => Applicative (Parser input) # | |
Applicative (MonadRandomState gen) # | |
Applicative f => Applicative (Rec1 * f) | Since: 4.9.0.0 |
Arrow a => Applicative (WrappedArrow a b) | Since: 2.1 |
Monoid m => Applicative (Const * m) | Since: 2.0.1 |
Applicative f => Applicative (Alt * f) | |
Monad m => Applicative (State s m) | |
Monad m => Applicative (Reader r m) | |
(Applicative m, Monad m) => Applicative (StateT s m) # | |
Applicative m => Applicative (ReaderT r m) # | |
AMPMonad m => Applicative (ExceptT e m) # | |
Monad m => Applicative (ZipSink i m) # | |
Applicative ((->) LiftedRep LiftedRep a) | Since: 2.1 |
(Applicative f, Applicative g) => Applicative ((:*:) * f g) | Since: 4.9.0.0 |
Applicative (Conduit i o m) # | |
Applicative f => Applicative (M1 * i c f) | Since: 4.9.0.0 |
(Applicative f, Applicative g) => Applicative ((:.:) * * f g) | Since: 4.9.0.0 |
Monad state => Applicative (Builder collection mutCollection step state err) | |
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.
Inject a value into the monadic type.
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.
As part of the MonadFail proposal (MFP), this function is moved
to its own class MonadFail
(see Control.Monad.Fail for more
details). The definition here will be removed in a future
release.
Instances
Monad [] | Since: 2.1 |
Monad Maybe | Since: 2.1 |
Monad IO | Since: 2.1 |
Monad Par1 | Since: 4.9.0.0 |
Monad P | Since: 2.1 |
Monad Min | Since: 4.9.0.0 |
Monad Max | Since: 4.9.0.0 |
Monad First | Since: 4.9.0.0 |
Monad Last | Since: 4.9.0.0 |
Monad Option | Since: 4.9.0.0 |
Monad NonEmpty | Since: 4.9.0.0 |
Monad Identity | Since: 4.8.0.0 |
Monad STM | Since: 4.3.0.0 |
Monad Dual | Since: 4.8.0.0 |
Monad Sum | Since: 4.8.0.0 |
Monad Product | Since: 4.8.0.0 |
Monad First | |
Monad Last | |
Monad ReadP | Since: 2.1 |
Monad DList # | |
Monad Partial # | |
Monad Gen # | |
Monad Check # | |
Monad (Either e) | Since: 4.4.0.0 |
Monad (U1 *) | Since: 4.9.0.0 |
Monoid a => Monad ((,) a) | Since: 4.9.0.0 |
Monad m => Monad (WrappedMonad m) | |
ArrowApply a => Monad (ArrowMonad a) | Since: 2.1 |
Monad (Proxy *) | Since: 4.7.0.0 |
Monad (ST s) | Since: 2.1 |
Monad m => Monad (ResourceT m) # | |
ParserSource input => Monad (Parser input) # | |
Monad (MonadRandomState gen) # | |
Monad f => Monad (Rec1 * f) | Since: 4.9.0.0 |
Monad f => Monad (Alt * f) | |
Monad m => Monad (State r m) | |
Monad m => Monad (Reader r m) | |
(Functor m, Monad m) => Monad (StateT s m) # | |
AMPMonad m => Monad (ReaderT r m) # | |
AMPMonad m => Monad (ExceptT e m) # | |
Monad ((->) LiftedRep LiftedRep r) | Since: 2.1 |
(Monad f, Monad g) => Monad ((:*:) * f g) | Since: 4.9.0.0 |
Monad (Conduit i o m) # | |
Monad f => Monad (M1 * i c f) | Since: 4.9.0.0 |
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 for string-like datastructures; used by the overloaded string extension (-XOverloadedStrings in GHC).
Minimal complete definition
Methods
fromString :: String -> a #
The IsList
class and its methods are intended to be used in
conjunction with the OverloadedLists extension.
Since: 4.7.0.0
Associated Types
The Item
type function returns the type of items of the structure
l
.
Methods
The fromList
function constructs the structure l
from the given
list of Item l
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.
The toList
function extracts a list of Item l
from the structure l
.
It should satisfy fromList . toList = id.
Instances
IsList CallStack | Be aware that 'fromList . toList = id' only for unfrozen Since: 4.9.0.0 |
IsList Version | Since: 4.8.0.0 |
IsList String | |
IsList AsciiString | |
IsList Bitmap # | |
IsList [a] | Since: 4.7.0.0 |
IsList (NonEmpty a) | Since: 4.9.0.0 |
IsList (Array ty) | |
PrimType ty => IsList (UArray ty) | |
PrimType ty => IsList (Block ty) | |
IsList c => IsList (NonEmpty c) | |
IsList (DList a) # | |
PrimType ty => IsList (ChunkedUArray ty) # | |
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
Minimal complete definition
Instances
class (Enum a, Eq a, Ord a, Integral a, IsIntegral a) => IsNatural a where #
Non Negative Number literals, convertible through the generic Natural type
Minimal complete definition
Instances
types that have sign and can be made absolute
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
Instances
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
Minimal complete definition
Associated Types
type Difference a :: * #
Methods
(-) :: a -> a -> Difference a infixl 6 #
Instances
class Multiplicative a where #
Represent class of things that can be multiplied together
x * midentity = x midentity * x = x
Methods
Identity element over multiplication
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
Instances
class (Additive a, Multiplicative a) => IDivisible a where #
Represent types that supports an euclidian division
(x ‘div‘ y) * y + (x ‘mod‘ y) == x
Instances
class Multiplicative a => Divisible a where #
Support for division between same types
This is likely to change to represent specific mathematic divisions
Minimal complete definition
Data types
The Maybe
type encapsulates an optional value. A value of type
either contains a value of type Maybe
aa
(represented as
),
or it is empty (represented as Just
aNothing
). Using Maybe
is a good way to
deal with errors or exceptional cases without resorting to drastic
measures such as error
.
The Maybe
type is also a monad. It is a simple kind of error
monad, where all errors are represented by Nothing
. A richer
error monad can be built using the Either
type.
Instances
Monad Maybe | Since: 2.1 |
Functor Maybe | Since: 2.1 |
Applicative Maybe | Since: 2.1 |
Foldable Maybe | Since: 2.1 |
Traversable Maybe | Since: 2.1 |
Alternative Maybe | Since: 2.1 |
MonadPlus Maybe | Since: 2.1 |
MonadFailure Maybe | |
Eq a => Eq (Maybe a) | |
Data a => Data (Maybe a) | Since: 4.0.0.0 |
Ord a => Ord (Maybe a) | |
Read a => Read (Maybe a) | Since: 2.1 |
Show a => Show (Maybe a) | |
Generic (Maybe a) | |
Semigroup a => Semigroup (Maybe a) | Since: 4.9.0.0 |
Monoid a => Monoid (Maybe a) | Lift a semigroup into Since: 2.1 |
SingKind a => SingKind (Maybe a) | Since: 4.9.0.0 |
NormalForm a => NormalForm (Maybe a) | |
Arbitrary a => Arbitrary (Maybe a) Source # | |
Generic1 * Maybe | |
SingI (Maybe a) (Nothing a) | Since: 4.9.0.0 |
SingI a1 a2 => SingI (Maybe a1) (Just a1 a2) | Since: 4.9.0.0 |
From (Maybe a) (Either () a) | |
type Failure Maybe | |
type Rep (Maybe a) | |
data Sing (Maybe a) | |
type DemoteRep (Maybe a) | |
type Rep1 * Maybe | |
type (==) (Maybe k) a b | |
Instances
Bounded Bool | Since: 2.1 |
Enum Bool | Since: 2.1 |
Eq Bool | |
Data Bool | Since: 4.0.0.0 |
Ord Bool | |
Read Bool | Since: 2.1 |
Show Bool | |
Ix Bool | Since: 2.1 |
Generic Bool | |
SingKind Bool | Since: 4.9.0.0 |
Storable Bool | Since: 2.1 |
Bits Bool | Interpret Since: 4.7.0.0 |
FiniteBits Bool | Since: 4.7.0.0 |
NormalForm Bool | |
Arbitrary Bool Source # | |
IsProperty Bool Source # | |
SingI Bool False | Since: 4.9.0.0 |
SingI Bool True | Since: 4.9.0.0 |
IsProperty (String, Bool) Source # | |
type Rep Bool | |
data Sing Bool | |
type DemoteRep Bool | |
type (==) Bool a b | |
The character type Char
is an enumeration whose values represent
Unicode (or equivalently ISO/IEC 10646) characters (see
http://www.unicode.org/ for details). This set extends the ISO 8859-1
(Latin-1) character set (the first 256 characters), which is itself an extension
of the ASCII character set (the first 128 characters). A character literal in
Haskell has type Char
.
To convert a Char
to or from the corresponding Int
value defined
by Unicode, use toEnum
and fromEnum
from the
Enum
class respectively (or equivalently ord
and chr
).
Instances
Bounded Char | Since: 2.1 |
Enum Char | Since: 2.1 |
Eq Char | |
Data Char | Since: 4.0.0.0 |
Ord Char | |
Read Char | Since: 2.1 |
Show Char | Since: 2.1 |
Ix Char | Since: 2.1 |
PrintfArg Char | Since: 2.1 |
IsChar Char | Since: 2.1 |
Storable Char | Since: 2.1 |
NormalForm Char | |
PrimType Char | |
PrimMemoryComparable Char | |
Subtractive Char | |
StorableFixed Char Source # | |
Storable Char Source # | |
Arbitrary Char Source # | |
Generic1 k (URec k Char) | |
Functor (URec * Char) | |
Foldable (URec * Char) | |
Traversable (URec * Char) | |
Eq (URec k Char p) | |
Ord (URec k Char p) | |
Show (URec k Char p) | |
Generic (URec k Char p) | |
type PrimSize Char | |
type Difference Char | |
type NatNumMaxBound Char | |
data URec k Char | Used for marking occurrences of Since: 4.9.0.0 |
type Rep1 k (URec k Char) | |
type Rep (URec k Char p) | |
ASCII value between 0x0 and 0x7f
A value of type
is a computation which, when performed,
does some I/O before returning a value of type IO
aa
.
There is really only one way to "perform" an I/O action: bind it to
Main.main
in your program. When your program is run, the I/O will
be performed. It isn't possible to perform I/O from an arbitrary
function, unless that function is itself in the IO
monad and called
at some point, directly or indirectly, from Main.main
.
IO
is a monad, so IO
actions can be combined using either the do-notation
or the >>
and >>=
operations from the Monad
class.
Instances
Monad IO | Since: 2.1 |
Functor IO | Since: 2.1 |
Applicative IO | Since: 2.1 |
MonadIO IO | Since: 4.9.0.0 |
Alternative IO | Since: 4.9.0.0 |
MonadPlus IO | Since: 4.9.0.0 |
PrimMonad IO | |
MonadBracket IO Source # | |
MonadCatch IO Source # | |
MonadThrow IO Source # | |
MonadRandom IO Source # | |
Semigroup a => Semigroup (IO a) | Since: 4.10.0.0 |
Monoid a => Monoid (IO a) | Since: 4.9.0.0 |
(~) * a () => PrintfType (IO a) | Since: 4.7.0.0 |
(~) * a () => HPrintfType (IO a) | Since: 4.7.0.0 |
type PrimVar IO | |
type PrimState IO | |
data Either a b :: * -> * -> * #
The Either
type represents values with two possibilities: a value of
type
is either Either
a b
or Left
a
.Right
b
The Either
type is sometimes used to represent a value which is
either correct or an error; by convention, the Left
constructor is
used to hold an error value and the Right
constructor is used to
hold a correct value (mnemonic: "right" also means "correct").
Examples
The type
is the type of values which can be either
a Either
String
Int
String
or an Int
. The Left
constructor can be used only on
String
s, and the Right
constructor can be used only on Int
s:
>>>
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 Int
s.
>>>
:{
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"
Instances
Bifunctor Either | Since: 4.8.0.0 |
Monad (Either e) | Since: 4.4.0.0 |
Functor (Either a) | Since: 3.0 |
Applicative (Either e) | Since: 3.0 |
Foldable (Either a) | Since: 4.7.0.0 |
Traversable (Either a) | Since: 4.7.0.0 |
MonadFailure (Either a) | |
Generic1 * (Either a) | |
From (Maybe a) (Either () a) | |
(Eq b, Eq a) => Eq (Either a b) | |
(Data a, Data b) => Data (Either a b) | Since: 4.0.0.0 |
(Ord b, Ord a) => Ord (Either a b) | |
(Read b, Read a) => Read (Either a b) | |
(Show b, Show a) => Show (Either a b) | |
Generic (Either a b) | |
Semigroup (Either a b) | Since: 4.9.0.0 |
(NormalForm l, NormalForm r) => NormalForm (Either l r) | |
(Arbitrary l, Arbitrary r) => Arbitrary (Either l r) Source # | |
From (Either a b) (These a b) | |
type Failure (Either a) | |
type Rep1 * (Either a) | |
type Rep (Either a b) | |
type (==) (Either k1 k2) a b | |
Numbers
8-bit signed integer type
Instances
Bounded Int8 | Since: 2.1 |
Enum Int8 | Since: 2.1 |
Eq Int8 | Since: 2.1 |
Integral Int8 | Since: 2.1 |
Data Int8 | Since: 4.0.0.0 |
Num Int8 | Since: 2.1 |
Ord Int8 | Since: 2.1 |
Read Int8 | Since: 2.1 |
Real Int8 | Since: 2.1 |
Show Int8 | Since: 2.1 |
Ix Int8 | Since: 2.1 |
PrintfArg Int8 | Since: 2.1 |
Storable Int8 | Since: 2.1 |
Bits Int8 | Since: 2.1 |
FiniteBits Int8 | Since: 4.6.0.0 |
NormalForm Int8 | |
PrimType Int8 | |
PrimMemoryComparable Int8 | |
Multiplicative Int8 | |
IDivisible Int8 | |
Additive Int8 | |
Subtractive Int8 | |
IsIntegral Int8 | |
Integral Int8 | |
HasNegation Int8 | |
Signed Int8 Source # | |
StorableFixed Int8 Source # | |
Storable Int8 Source # | |
Arbitrary Int8 Source # | |
Hashable Int8 Source # | |
From Int8 Int | |
From Int8 Int16 | |
From Int8 Int32 | |
From Int8 Int64 | |
Cast Int8 Word8 | |
Cast Word8 Int8 | |
IntegralDownsize Int Int8 | |
IntegralDownsize Int64 Int8 | |
IntegralDownsize Integer Int8 | |
IntegralUpsize Int8 Int | |
IntegralUpsize Int8 Int16 | |
IntegralUpsize Int8 Int32 | |
IntegralUpsize Int8 Int64 | |
type PrimSize Int8 | |
type Difference Int8 | |
type NatNumMaxBound Int8 | |
16-bit signed integer type
Instances
32-bit signed integer type
Instances
64-bit signed integer type
Instances
8-bit unsigned integer type
Instances
16-bit unsigned integer type
Instances
32-bit unsigned integer type
Instances
64-bit unsigned integer type
Instances
Instances
128 bits Word
Instances
256 bits Word
Instances
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
Invariant: Jn#
and Jp#
are used iff value doesn't fit in S#
Useful properties resulting from the invariants:
Instances
Enum Integer | Since: 2.1 |
Eq Integer | |
Integral Integer | Since: 2.0.1 |
Data Integer | Since: 4.0.0.0 |
Num Integer | Since: 2.1 |
Ord Integer | |
Read Integer | Since: 2.1 |
Real Integer | Since: 2.0.1 |
Show Integer | Since: 2.1 |
Ix Integer | Since: 2.1 |
PrintfArg Integer | Since: 2.1 |
Bits Integer | Since: 2.1 |
NormalForm Integer | |
Multiplicative Integer | |
Multiplicative Rational | |
IDivisible Integer | |
Divisible Rational | |
Additive Integer | |
Subtractive Integer | |
IsIntegral Integer | |
Integral Integer | |
Fractional Rational | |
HasNegation Integer | |
IntegralRounding Rational Source # | |
Signed Integer Source # | |
Arbitrary Integer Source # | |
Hashable Integer Source # | |
IsIntegral n => From n Integer | |
IntegralDownsize Integer Int8 | |
IntegralDownsize Integer Int16 | |
IntegralDownsize Integer Int32 | |
IntegralDownsize Integer Int64 | |
IntegralDownsize Integer Natural | |
IntegralDownsize Integer Word8 | |
IntegralDownsize Integer Word16 | |
IntegralDownsize Integer Word32 | |
IntegralDownsize Integer Word64 | |
IsIntegral a => IntegralUpsize a Integer | |
type Difference Integer | |
Type representing arbitrary-precision non-negative integers.
Operations whose result would be negative
.throw
(Underflow
:: ArithException
)
Since: 4.8.0.0
Instances
Enum Natural | Since: 4.8.0.0 |
Eq Natural | |
Integral Natural | Since: 4.8.0.0 |
Data Natural | Since: 4.8.0.0 |
Num Natural | Since: 4.8.0.0 |
Ord Natural | |
Read Natural | Since: 4.8.0.0 |
Real Natural | Since: 4.8.0.0 |
Show Natural | Since: 4.8.0.0 |
Ix Natural | Since: 4.8.0.0 |
PrintfArg Natural | Since: 4.8.0.0 |
Bits Natural | Since: 4.8.0.0 |
NormalForm Natural | |
Multiplicative Natural | |
IDivisible Natural | |
Additive Natural | |
Subtractive Natural | |
IsIntegral Natural | |
IsNatural Natural | |
Integral Natural | |
Arbitrary Natural Source # | |
Hashable Natural Source # | |
IsNatural n => From n Natural | |
IntegralDownsize Integer Natural | |
IntegralDownsize Natural Word8 | |
IntegralDownsize Natural Word16 | |
IntegralDownsize Natural Word32 | |
IntegralDownsize Natural Word64 | |
IsNatural a => IntegralUpsize a Natural | |
type Difference Natural | |
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 | Since: 2.1 |
Data Float | Since: 4.0.0.0 |
Ord Float | |
Read Float | Since: 2.1 |
RealFloat Float | Since: 2.1 |
PrintfArg Float | Since: 2.1 |
Storable Float | Since: 2.1 |
NormalForm Float | |
PrimType Float | |
Multiplicative Float | |
Divisible Float | |
Additive Float | |
Subtractive Float | |
Integral Float | |
Fractional Float | |
HasNegation Float | |
Trigonometry Float Source # | |
FloatingPoint Float Source # | |
IntegralRounding Float Source # | |
Signed Float Source # | |
StorableFixed Float Source # | |
Storable Float Source # | |
Arbitrary Float Source # | |
Generic1 k (URec k Float) | |
Functor (URec * Float) | |
Foldable (URec * Float) | |
Traversable (URec * Float) | |
Eq (URec k Float p) | |
Ord (URec k Float p) | |
Show (URec k Float p) | |
Generic (URec k Float p) | |
type PrimSize Float | |
type Difference Float | |
data URec k Float | Used for marking occurrences of Since: 4.9.0.0 |
type Rep1 k (URec k Float) | |
type Rep (URec k Float p) | |
Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.
Instances
Eq Double | |
Floating Double | Since: 2.1 |
Data Double | Since: 4.0.0.0 |
Ord Double | |
Read Double | Since: 2.1 |
RealFloat Double | Since: 2.1 |
PrintfArg Double | Since: 2.1 |
Storable Double | Since: 2.1 |
NormalForm Double | |
PrimType Double | |
Multiplicative Double | |
Divisible Double | |
Additive Double | |
Subtractive Double | |
Integral Double | |
Fractional Double | |
HasNegation Double | |
Trigonometry Double Source # | |
FloatingPoint Double Source # | |
IntegralRounding Double Source # | |
Signed Double Source # | |
StorableFixed Double Source # | |
Storable Double Source # | |
Arbitrary Double Source # | |
Generic1 k (URec k Double) | |
Functor (URec * Double) | |
Foldable (URec * Double) | |
Traversable (URec * Double) | |
Eq (URec k Double p) | |
Ord (URec k Double p) | |
Show (URec k Double p) | |
Generic (URec k Double p) | |
type PrimSize Double | |
type Difference Double | |
data URec k Double | Used for marking occurrences of Since: 4.9.0.0 |
type Rep1 k (URec k Double) | |
type Rep (URec k Double p) | |
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.
Instances
From Word (CountOf ty) | |
TryFrom Int (CountOf ty) | |
Enum (CountOf ty) | |
Eq (CountOf ty) | |
Num (CountOf ty) | |
Ord (CountOf ty) | |
Show (CountOf ty) | |
Semigroup (CountOf ty) | |
Monoid (CountOf ty) | |
NormalForm (CountOf a) | |
Additive (CountOf ty) | |
Subtractive (CountOf ty) | |
IsIntegral (CountOf ty) | |
IsNatural (CountOf ty) | |
Integral (CountOf ty) | |
Arbitrary (CountOf ty) Source # | |
From (CountOf ty) Word | |
From (CountOf ty) Int | |
type Difference (CountOf ty) | |
type NatNumMaxBound (CountOf x) | |
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.
Instances
From Word (Offset ty) | |
TryFrom Int (Offset ty) | |
Enum (Offset ty) | |
Eq (Offset ty) | |
Num (Offset ty) | |
Ord (Offset ty) | |
Show (Offset ty) | |
NormalForm (Offset a) | |
Additive (Offset ty) | |
Subtractive (Offset ty) | |
IsIntegral (Offset ty) | |
IsNatural (Offset ty) | |
Integral (Offset ty) | |
type Difference (Offset ty) | |
type NatNumMaxBound (Offset x) | |
Collection types
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
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.
Minimal complete definition
primSizeInBytes, primShiftToBytes, primBaUIndex, primMbaURead, primMbaUWrite, primAddrIndex, primAddrRead, primAddrWrite
Instances
Array of a
Instances
Functor Array | |
Mappable Array Source # | |
IsList (Array ty) | |
Eq a => Eq (Array a) | |
Data ty => Data (Array ty) | |
Ord a => Ord (Array a) | |
Show a => Show (Array a) | |
Semigroup (Array a) | |
Monoid (Array a) | |
NormalForm a => NormalForm (Array a) | |
Copy (Array ty) Source # | |
Collection (Array ty) Source # | |
Buildable (Array ty) Source # | |
Fold1able (Array ty) Source # | |
Foldable (Array ty) Source # | |
IndexedCollection (Array ty) Source # | |
InnerFunctor (Array ty) Source # | |
Sequential (Array ty) Source # | |
BoxedZippable (Array ty) Source # | |
Zippable (Array ty) Source # | |
Hashable a => Hashable (Array a) Source # | |
PrimType ty => From (Array ty) (UArray ty) | |
PrimType ty => From (Array ty) (Block ty) | |
PrimType ty => From (UArray ty) (Array ty) | |
(NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) => TryFrom (Array ty) (BlockN n ty) | |
(NatWithinBound Int n, PrimType ty) => From (BlockN n ty) (Array ty) | |
type Item (Array ty) | |
type Element (Array ty) Source # | |
type Mutable (Array ty) Source # | |
type Step (Array ty) Source # | |
Opaque packed array of characters in the UTF8 encoding
Instances
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
The class of semigroups (types with an associative binary operation).
Since: 4.9.0.0
Instances
Semigroup Ordering | Since: 4.9.0.0 |
Semigroup () | Since: 4.9.0.0 |
Semigroup Void | Since: 4.9.0.0 |
Semigroup Event | Since: 4.10.0.0 |
Semigroup Lifetime | Since: 4.10.0.0 |
Semigroup All | Since: 4.9.0.0 |
Semigroup Any | Since: 4.9.0.0 |
Semigroup Builder | |
Semigroup String | |
Semigroup AsciiString | |
Semigroup Bitmap # | |
Semigroup FileName # | |
Semigroup [a] | Since: 4.9.0.0 |
Semigroup a => Semigroup (Maybe a) | Since: 4.9.0.0 |
Semigroup a => Semigroup (IO a) | Since: 4.10.0.0 |
Ord a => Semigroup (Min a) | Since: 4.9.0.0 |
Ord a => Semigroup (Max a) | Since: 4.9.0.0 |
Semigroup (First a) | Since: 4.9.0.0 |
Semigroup (Last a) | Since: 4.9.0.0 |
Monoid m => Semigroup (WrappedMonoid m) | Since: 4.9.0.0 |
Semigroup a => Semigroup (Option a) | Since: 4.9.0.0 |
Semigroup (NonEmpty a) | Since: 4.9.0.0 |
Semigroup a => Semigroup (Identity a) | Since: 4.9.0.0 |
Semigroup a => Semigroup (Dual a) | Since: 4.9.0.0 |
Semigroup (Endo a) | Since: 4.9.0.0 |
Num a => Semigroup (Sum a) | Since: 4.9.0.0 |
Num a => Semigroup (Product a) | Since: 4.9.0.0 |
Semigroup (First a) | Since: 4.9.0.0 |
Semigroup (Last a) | Since: 4.9.0.0 |
Semigroup (Array a) | |
PrimType ty => Semigroup (UArray ty) | |
PrimType ty => Semigroup (Block ty) | |
Semigroup (CountOf ty) | |
Semigroup (DList a) # | |
Semigroup (ChunkedUArray a) # | |
Semigroup b => Semigroup (a -> b) | Since: 4.9.0.0 |
Semigroup (Either a b) | Since: 4.9.0.0 |
(Semigroup a, Semigroup b) => Semigroup (a, b) | Since: 4.9.0.0 |
Semigroup (Proxy k s) | Since: 4.9.0.0 |
(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) | Since: 4.9.0.0 |
Semigroup a => Semigroup (Const k a b) | Since: 4.9.0.0 |
Alternative f => Semigroup (Alt * f a) | Since: 4.9.0.0 |
(Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) | Since: 4.9.0.0 |
(Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) | Since: 4.9.0.0 |
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 newtype
s and make those instances
of Monoid
, e.g. Sum
and Product
.
Methods
Identity of mappend
An associative operation
Fold a list using the monoid.
For most types, the default definition for mconcat
will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
Instances
Monoid Ordering | Since: 2.1 |
Monoid () | Since: 2.1 |
Monoid EventLifetime | Since: 4.8.0.0 |
Monoid Event | Since: 4.3.1.0 |
Monoid Lifetime |
Since: 4.8.0.0 |
Monoid All | Since: 2.1 |
Monoid Any | Since: 2.1 |
Monoid Builder | |
Monoid String | |
Monoid AsciiString | |
Monoid Bitmap # | |
Monoid FileName # | |
Monoid [a] | Since: 2.1 |
Monoid a => Monoid (Maybe a) | Lift a semigroup into Since: 2.1 |
Monoid a => Monoid (IO a) | Since: 4.9.0.0 |
(Ord a, Bounded a) => Monoid (Min a) | Since: 4.9.0.0 |
(Ord a, Bounded a) => Monoid (Max a) | Since: 4.9.0.0 |
Monoid m => Monoid (WrappedMonoid m) | Since: 4.9.0.0 |
Semigroup a => Monoid (Option a) | Since: 4.9.0.0 |
Monoid a => Monoid (Identity a) | |
Monoid a => Monoid (Dual a) | Since: 2.1 |
Monoid (Endo a) | Since: 2.1 |
Num a => Monoid (Sum a) | Since: 2.1 |
Num a => Monoid (Product a) | Since: 2.1 |
Monoid (First a) | Since: 2.1 |
Monoid (Last a) | Since: 2.1 |
Monoid (Array a) | |
PrimType ty => Monoid (UArray ty) | |
PrimType ty => Monoid (Block ty) | |
Monoid (CountOf ty) | |
Monoid (DList a) # | |
Monoid (ChunkedUArray a) # | |
Monoid b => Monoid (a -> b) | Since: 2.1 |
(Monoid a, Monoid b) => Monoid (a, b) | Since: 2.1 |
Monoid (Proxy k s) | Since: 4.7.0.0 |
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | Since: 2.1 |
Monoid a => Monoid (Const k a b) | |
Alternative f => Monoid (Alt * f a) | Since: 4.8.0.0 |
(Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | Since: 2.1 |
(Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) | Since: 2.1 |
Collection
class (IsList c, Item c ~ Element c) => Collection c where Source #
A set of methods for ordered colection
Methods
Check if a collection is empty
length :: c -> CountOf (Element c) Source #
Length of a collection (number of Element c)
elem :: forall a. (Eq a, a ~ Element c) => Element c -> c -> Bool Source #
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 Source #
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 Source #
Get the maximum element of a collection
minimum :: forall a. (Ord a, a ~ Element c) => NonEmpty c -> Element c Source #
Get the minimum element of a collection
any :: (Element c -> Bool) -> c -> Bool Source #
Determine is any elements of the collection satisfy the predicate
all :: (Element c -> Bool) -> c -> Bool Source #
Determine is all elements of the collection satisfy the predicate
Instances
Collection String Source # | |
Collection AsciiString Source # | |
Collection Bitmap Source # | |
Collection [a] Source # | |
Collection (Array ty) Source # | |
PrimType ty => Collection (UArray ty) Source # | |
PrimType ty => Collection (Block ty) Source # | |
Collection c => Collection (NonEmpty c) Source # | |
Collection (DList a) Source # | |
PrimType ty => Collection (ChunkedUArray ty) Source # | |
and :: (Collection col, Element col ~ Bool) => col -> Bool Source #
Return True if all the elements in the collection are True
or :: (Collection col, Element col ~ Bool) => col -> Bool Source #
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 Source #
A set of methods for ordered colection
Minimal complete definition
(take, drop | splitAt), (revTake, revDrop | revSplitAt), splitOn, (break | span), (breakEnd | spanEnd), intersperse, filter, reverse, uncons, unsnoc, snoc, cons, find, sortBy, singleton, replicate
Methods
take :: CountOf (Element c) -> c -> c Source #
Take the first @n elements of a collection
revTake :: CountOf (Element c) -> c -> c Source #
Take the last @n elements of a collection
drop :: CountOf (Element c) -> c -> c Source #
Drop the first @n elements of a collection
revDrop :: CountOf (Element c) -> c -> c Source #
Drop the last @n elements of a collection
splitAt :: CountOf (Element c) -> c -> (c, c) Source #
Split the collection at the @n'th elements
revSplitAt :: CountOf (Element c) -> c -> (c, c) Source #
Split the collection at the @n'th elements from the end
splitOn :: (Element c -> Bool) -> c -> [c] Source #
Split on a specific elements returning a list of colletion
break :: (Element c -> Bool) -> c -> (c, c) Source #
Split a collection when the predicate return true
breakEnd :: (Element c -> Bool) -> c -> (c, c) Source #
Split a collection when the predicate return true
breakElem :: Eq (Element c) => Element c -> c -> (c, c) Source #
Split a collection when the predicate return true starting from the end of the collection
takeWhile :: (Element c -> Bool) -> c -> c Source #
Return the longest prefix in the collection that satisfy the predicate
dropWhile :: (Element c -> Bool) -> c -> c Source #
Return the longest prefix in the collection that satisfy the predicate
intersperse :: Element c -> c -> c Source #
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 Source #
intercalate
xs xss
is equivalent to (
.
It inserts the list mconcat
(intersperse
xs xss))xs
in between the lists in xss
and concatenates the
result.
span :: (Element c -> Bool) -> c -> (c, c) Source #
Split a collection while the predicate return true
spanEnd :: (Element c -> Bool) -> c -> (c, c) Source #
Split a collection while the predicate return true starting from the end of the collection
filter :: (Element c -> Bool) -> c -> c Source #
Filter all the elements that satisfy the predicate
partition :: (Element c -> Bool) -> c -> (c, c) Source #
Partition the elements thtat satisfy the predicate and those that don't
Reverse a collection
uncons :: c -> Maybe (Element c, c) Source #
Decompose a collection into its first element and the remaining collection. If the collection is empty, returns Nothing.
unsnoc :: c -> Maybe (c, Element c) Source #
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 Source #
Prepend an element to an ordered collection
cons :: Element c -> c -> c Source #
Append an element to an ordered collection
find :: (Element c -> Bool) -> c -> Maybe (Element c) Source #
Find an element in an ordered collection
sortBy :: (Element c -> Element c -> Ordering) -> c -> c Source #
Sort an ordered collection using the specified order function
singleton :: Element c -> c Source #
Create a collection with a single element
head :: NonEmpty c -> Element c Source #
get the first element of a non-empty collection
last :: NonEmpty c -> Element c Source #
get the last element of a non-empty collection
tail :: NonEmpty c -> c Source #
Extract the elements after the first element of a non-empty collection.
init :: NonEmpty c -> c Source #
Extract the elements before the last element of a non-empty collection.
replicate :: CountOf (Element c) -> Element c -> c Source #
Create a collection where the element in parameter is repeated N time
isPrefixOf :: Eq (Element c) => c -> c -> Bool Source #
Takes two collections and returns True iff the first collection is a prefix of the second.
isPrefixOf :: Eq c => c -> c -> Bool Source #
Takes two collections and returns True iff the first collection is a prefix of the second.
isSuffixOf :: Eq (Element c) => c -> c -> Bool Source #
Takes two collections and returns True iff the first collection is a suffix of the second.
isSuffixOf :: Eq c => c -> c -> Bool Source #
Takes two collections and returns True iff the first collection is a suffix of the second.
isInfixOf :: Eq (Element c) => c -> c -> Bool Source #
Takes two collections and returns True iff the first collection is an infix of the second.
isInfixOf :: Eq c => c -> c -> Bool Source #
Takes two collections and returns True iff the first collection is an infix of the second.
stripPrefix :: Eq (Element c) => c -> c -> Maybe c Source #
Try to strip a prefix from a collection
stripSuffix :: Eq (Element c) => c -> c -> Maybe c Source #
Try to strip a suffix from a collection
Instances
Sequential String Source # | |
Sequential AsciiString Source # | |
Sequential Bitmap Source # | |
Sequential [a] Source # | |
Sequential (Array ty) Source # | |
PrimType ty => Sequential (UArray ty) Source # | |
PrimType ty => Sequential (Block ty) Source # | |
Sequential (DList a) Source # | |
PrimType ty => Sequential (ChunkedUArray ty) Source # | |
NonEmpty property for any Collection
nonEmpty :: Collection c => c -> Maybe (NonEmpty c) Source #
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 Source #
Give the ability to fold a collection on itself
Methods
foldl' :: (a -> Element collection -> a) -> a -> collection -> a Source #
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 Source #
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 Source #
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
. If this is Maybe
bNothing
, no element
is added on to the result list. If it is
, then Just
bb
is
included in the result list.
Examples
Using
is a shortcut for mapMaybe
f x
in most cases:catMaybes
$ map
f x
>>>
import Text.Read ( readMaybe )
>>>
let readMaybeInt = readMaybe :: String -> Maybe Int
>>>
mapMaybe readMaybeInt ["1", "Foo", "3"]
[1,3]>>>
catMaybes $ map readMaybeInt ["1", "Foo", "3"]
[1,3]
If we map the Just
constructor, the entire list should be returned:
>>>
mapMaybe Just [1,2,3]
[1,2,3]
catMaybes :: [Maybe a] -> [a] #
The catMaybes
function takes a list of Maybe
s 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
listToMaybe :: [a] -> Maybe a #
The listToMaybe
function returns Nothing
on an empty list
or
where Just
aa
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
should be the same
pair as partitionEithers
x(
:lefts
x, rights
x)
>>>
let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]
>>>
partitionEithers list == (lefts list, rights list)
True
Function
Applicative
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap
.
The name of this operator is an allusion to $
.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $
is function application, <$>
is function
application lifted over a Functor
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an Either
Int
Int
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 infixl 3 #
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 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 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 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 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 MismatchedParenthesescatch
e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses)) Caught MismatchedParentheses *Main> throw MismatchedParenthesescatch
e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException)) Caught MismatchedParentheses *Main> throw MismatchedParenthesescatch
e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException)) Caught MismatchedParentheses *Main> throw MismatchedParenthesescatch
e -> putStrLn ("Caught " ++ show (e :: IOException)) *** Exception: MismatchedParentheses
Methods
toException :: e -> SomeException #
fromException :: SomeException -> Maybe e #
displayException :: e -> String #
Instances
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
.
Instances
Show SomeException | Since: 3.0 |
Exception SomeException | Since: 3.0 |
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.
Instances
Eq IOException | Since: 4.1.0.0 |
Show IOException | Since: 4.1.0.0 |
Exception IOException | Since: 4.1.0.0 |
Proxy
data Proxy k (t :: k) :: forall k. k -> * #
A concrete, poly-kinded proxy type
Constructors
Proxy |
Instances
Generic1 k (Proxy k) | |
Monad (Proxy *) | Since: 4.7.0.0 |
Functor (Proxy *) | Since: 4.7.0.0 |
Applicative (Proxy *) | Since: 4.7.0.0 |
Foldable (Proxy *) | Since: 4.7.0.0 |
Traversable (Proxy *) | Since: 4.7.0.0 |
Alternative (Proxy *) | Since: 4.9.0.0 |
MonadPlus (Proxy *) | Since: 4.9.0.0 |
Bounded (Proxy k t) | |
Enum (Proxy k s) | Since: 4.7.0.0 |
Eq (Proxy k s) | Since: 4.7.0.0 |
Data t => Data (Proxy * t) | Since: 4.7.0.0 |
Ord (Proxy k s) | Since: 4.7.0.0 |
Read (Proxy k s) | Since: 4.7.0.0 |
Show (Proxy k s) | Since: 4.7.0.0 |
Ix (Proxy k s) | Since: 4.7.0.0 |
Generic (Proxy k t) | |
Semigroup (Proxy k s) | Since: 4.9.0.0 |
Monoid (Proxy k s) | Since: 4.7.0.0 |
type Rep1 k (Proxy k) | |
type Rep (Proxy k t) | |
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
Partialiality wrapper.
partial :: a -> Partial a Source #
Create a value that is partial. this can only be
unwrap using the fromPartial
function
data PartialError Source #
An error related to the evaluation of a Partial value that failed.
it contains the name of the function and the reason for failure
Instances
fromPartial :: Partial a -> a Source #
Dewrap a possible partial value
ifThenElse :: Bool -> a -> a -> a #
for support of if .. then .. else