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 c a. 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. 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 :: forall r. forall a. 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 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 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 Int :: *
- data Integer :: *
- data Natural :: *
- type Rational = Ratio Integer
- data Float :: *
- data Double :: *
- newtype Size ty = Size Int
- newtype Offset ty = Offset 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 Monoid a where
- (<>) :: Monoid m => m -> m -> m
- class (IsList c, Item c ~ Element c) => Collection c where
- 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
- data SomeException :: *
- data IOException :: *
- data Proxy k t :: 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.
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 # | |
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 # | |
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
Nthable 1 (Tuple4 a b c d) Source # | |
Nthable 2 (Tuple4 a b c d) Source # | |
Nthable 3 (Tuple4 a b c d) Source # | |
Nthable 4 (Tuple4 a b c d) Source # | |
(Eq d, Eq c, Eq b, Eq a) => Eq (Tuple4 a b c d) Source # | |
(Data d, Data c, Data b, Data a) => Data (Tuple4 a b c d) Source # | |
(Ord d, Ord c, Ord b, Ord a) => Ord (Tuple4 a b c d) Source # | |
(Show d, Show c, Show b, Show a) => Show (Tuple4 a b c d) Source # | |
Generic (Tuple4 a b c d) Source # | |
Thdable (Tuple4 a b c d) Source # | |
Sndable (Tuple4 a b c d) Source # | |
Fstable (Tuple4 a b c d) Source # | |
(Hashable a, Hashable b, Hashable c, Hashable d) => Hashable (Tuple4 a b c d) Source # | |
type NthTy 1 (Tuple4 a b c d) Source # | |
type NthTy 2 (Tuple4 a b c d) Source # | |
type NthTy 3 (Tuple4 a b c d) Source # | |
type NthTy 4 (Tuple4 a b c d) Source # | |
type Rep (Tuple4 a b c d) Source # | |
type ProductThird (Tuple4 a b c d) Source # | |
type ProductSecond (Tuple4 a b c d) Source # | |
type ProductFirst (Tuple4 a b c d) Source # | |
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 :: forall r. forall a. HasCallStack => String -> a Source #
stop execution and displays an error message
getArgs :: IO [String] Source #
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.
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 Source #
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
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