-
Notifications
You must be signed in to change notification settings - Fork 0
Foundation
Markus Færevaag edited this page Jun 13, 2014
·
2 revisions
This documentation is similar, and partly based on, Haskell's documentation of Prelude.
pi :: Float
- The constant π (3.14159265359)
id :: a -> a
- Identity function
{.} :: (b -> c) -> (a -> b) -> (a -> c)
- Function composition
flip :: (a -> b -> c) -> (b -> a -> c)
-
flip ftakes its (first) two arguments in the reverse order off.
not :: Bool -> Bool
- Logical NOT
{&&} :: Bool -> Bool -> Bool
- Logical AND
{||} :: Bool -> Bool -> Bool
- Logical OR
{==} :: a -> a -> Bool
- Equality (built-in)
{/=} :: a -> a -> Bool
- Negated equality
{<=} :: a -> a -> Bool
- Logical less-than or equals (built-in)
{<} :: a -> a -> Bool
- Logical less-than
{>} :: a -> a -> Bool
- Logical greater-than
{>=} :: a -> a -> Bool
- Logical greater-than or equals
asPair :: a -> b -> (a, b)
- Pairs two first arguments
{<>} :: a -> b -> (a, b)
- Infix operator for
asPair
fst :: (a, b) -> a
- First element of pair
snd :: (a, b) -> b
- Second element of pair
{#} :: [a] -> Int -> a
- List index
length :: [a] -> Int
- Length of list
empty :: [a] -> Bool
- Test for empty list
head :: [a] -> a
- First element of list
tail :: [a] -> [a]
- Elements of list, after head
init :: [a] -> [a]
- Elements of list, except head
last :: [a] -> a
- Last element of list
{++} :: [a] -> [a] -> [a]
- Join two lists
map :: (a -> b) -> [a] -> [b]
-
map f xsis the list of results, of applyingfto each element inxs
fold :: (a -> b -> a) -> a -> [b] -> a
-
fold, applied to a binary operator, a starting value and a list, reduces the list using the binary operator, from left to right
fold1 :: (a -> b -> a) -> [b] -> a
-
fold1, applied to a binary operator and a list, reduces the list using the binary operator, from left to right, with head as starting value
filter :: (a -> Bool) -> [a] -> [a]
-
filter f xsreturns the list of results which holds for the predicate functionf, wherefis applied to each element inxs
take :: Int -> [a] -> [a]
-
take n xsreturns thenfirst elements inxs
drop :: Int -> [a] -> [a]
-
drop n xsreturns the elements ofxs, after thenfirst elements
zip :: [a] -> [b] -> [(a, b)]
-
ziptakes two lists and returns a list of corresponding pairs. If one input list is short, excess elements of the longer list are discarded
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
-
zipWithtakes a function and two lists, and returns a the function applied to an element of the first list and the corresponding element of the second list. If one input list is short, excess elements of the longer list are discarded
and :: [Bool] -> Bool
- Conjunction of Boolean list
or :: [Bool] -> Bool
- Disjunction of Boolean list
all :: (a -> Bool) -> [a] -> Bool
-
all f xstests if all elements inxshold for predicate functionsf, wherefis applied to each element
any :: (a -> Bool) -> [a] -> Bool
-
any f xstests if any of the elements inxshold for predicate functionsf, wherefis applied to each element
flatten :: [[a]] -> [a]
- Concatenates all lists into single list
flatMap :: ([a] -> [b]) -> [[a]] -> [b]
-
flatMap f xsapplies each list inxsto functionfand flattens the result into single list
elem :: a -> [a] -> Bool
-
elem x xstests if elementxis inxs
reverse :: [a] -> [a]
- Returns list in reverse order
union :: [a] -> [a] -> [a]
- Returns the list of all distinct elements in both lists (∪ in set-theory)
intersect :: [a] -> [a] -> [a]
- Returns the list of elements which exists in both lists (∩ in set-theory)
sortBy :: (a -> a -> Bool) -> [a] -> [a]
- Sort list by predicate function
sort :: [a] -> [a]
- Sort list with quick-sort algorithm
range :: Int -> Int -> [Int]
-
range x yreturns a list of Integer numbers ranging fromxtoy
rangeStep :: Int -> Int -> Int -> [Int]
-
rangeStep x y zreturns a list of Integer numbers ranging fromx,x + z,x + 2zup toy
{**} :: Int -> Int -> Int
- Exponentiation
pow :: Int -> Int -> Int -> Int
- Exponentiation with base
sum :: [a] -> a
- Sum of elements in list
product :: [a] -> a
- Product of elements in list
min :: a -> a -> a
- Smallest of two arguments
max :: a -> a -> a
- Largest of two arguments
minimum :: [a] -> a
- Smallest element in list
maximum :: [a] -> a
- Largest element in list
even :: Int -> Bool
- Test if number is even
odd :: Int -> Bool
- Test if number is odd
negate :: Int -> Int
- Negate Integer number
negatef :: Float -> Float
- Negate Float number
abs :: Int -> Int
- Absolute value of Integer number
while :: (a -> Bool) -> (a -> a) -> a -> a
-
while p f xappliesftox, whilep xis True
until :: (a -> Bool) -> (a -> a) -> a -> a
-
until p f xappliesftox, untilp xbecomes False