You are here: UUCS>Helium Web>Documentation>ATourOfTheHeliumPrelude (26 Jun 2008, JurriaanHage)EditAttach

Below you can find an overview of the functions made available by the Helium Prelude.
Note that currently, only the non-overloaded form of the Prelude is described. This ought to change soon.
If you have any corrections, remarks or additions to make, please contact us.
`
`**A** abs, all, and,
any **B** break **C**
ceiling, chr, concat,
concatMap, const, cos
**D** div, drop, dropWhile
**E** elemBy, eqBool,
eqChar, eqList, eqString,
error, even, exp
**F** filter, flip,
floor, foldl, foldl1,
foldr, foldr1, fromInt,
fst **G** gcd **H** head
**I** id, init, isAlpha,
isDigit, isLower,
isSpace, isUpper,
iterate **L** last,
lcm, length, lines,
log **M** map, max,
maximum, min, minimum,
mod **N** not, notElemBy,
null **O** odd, or,
ord, ordChar, ordFloat,
ordInt, ordList,
ordString **P** pi,
putStr, product **Q**
quot **R** readInt,
rem, repeat, replicate,
reverse, round, **S**
showInt,
signum, signumFloat,
sin, snd, span,
splitAt, sqrt, subtract,
sum **T** tail, take,
takeWhile, tan, toLower,
toUpper, truncate **U**
undefined, unlines,
until, unwords **W**
words **Z** zip, zipWith
**Boolean operators** (&&),
(||)
**Integer operators** (*),
(/), (+), (-),
(^) (/=), (==),
(<), (<=), (>),
(>=)
**Floating-point operators** (*.),
(/.), (+.), (-.),
(^.) (/=.), (==.),
(<.), (<=.), (>.),
(>=.) (**.)
**Other operators** (!!), (:),
(++), (.)

-- JurriaanHage - 09 Apr 2008

type: |
abs :: Int -> Int |

description: |
returns the absolute value of a number. |

definition: |
abs x | x >= 0 = x | otherwise = -x |

usage: |
Prelude> abs (-3) 3 |

type: |
all :: (a -> Bool) -> [a] -> Bool |

description: |
applied to a predicate and a list, returns True if all elements of the list satisfy the predicate, and False otherwise. Similar to the function any. |

definition: |
all p xs = and (map p xs) |

usage: |
Prelude> all (< 11) [1..10] True Prelude> all isDigit "123abc" False |

type: |
and :: [Bool] -> Bool |

description: |
takes the logical conjunction of a list of boolean values (see also `or'). |

definition: |
and xs = foldr (&&) True xs |

usage: |
Prelude> and [True, True, False, True] False Prelude> and [True, True, True, True] True Prelude> and [] True |

type: |
any :: (a -> Bool) -> [a] -> Bool |

description: |
applied to a predicate and a list, returns True if any of the elements of the list satisfy the predicate, and False otherwise. Similar to the function all. |

definition: |
any p xs = or (map p xs) |

usage: |
Prelude> any (< 11) [1..10] True Prelude> any isDigit "123abc" True Prelude> any isDigit "alphabetics" False |

type: |
break :: (a -> Bool) -> [a] -> ([a],[a]) |

description: |
given a predicate and a list, breaks the list into two lists (returned as a tuple) at the point where the predicate is first satisfied. If the predicate is never satisfied then the first element of the resulting tuple is the entire list and the second element is the empty list ([]). |

definition: |
break p xs = span p' xs where p' x = not (p x) |

usage: |
Prelude> break isSpace "hello there fred" ("hello", " there fred") Prelude> break isDigit "no digits here" ("no digits here","") |

type: |
ceiling :: Float -> Int |

description: |
returns the smallest integer not less than its argument. |

usage: |
Prelude> ceiling 3.8 4 Prelude> ceiling (-.3.8) -3 |

see also: |
floor |

type: |
chr :: Int -> Char |

description: |
applied to an integer in the range 0 -- 255, returns the character whose ascii code is that integer. It is the converse of the function ord. An error will result if chr is applied to an integer outside the correct range. |

definition: |
defined internally. |

usage: |
Prelude> chr 65 'A' Prelude> (ord (chr 65)) == 65 True |

see also: |
ord |

type: |
concat :: a -> [a] |

description: |
applied to a list of lists, joins them together using the ++ operator. |

definition: |
concat xs = foldr (++) [] xs |

usage: |
Prelude> concat [[1,2,3], [4], [], [5,6,7,8]] [1, 2, 3, 4, 5, 6, 7, 8] |

type: |
concatMap :: (a -> [b]) -> [a] -> [b] |

description: |
given a function which maps a value to a list, and a list of elements of the same type as the value, applies the function to the list and then concatenates the result (thus flattening the resulting list). |

definition: |
concatMap f = concat . map f |

usage: |
Prelude> concatMap showInt [1,2,3,4] "1234" |

type: |
const :: const :: a -> b -> a |

description: |
creates a constant valued function which always has the value of its first argument, regardless of the value of its second argument. |

definition: |
const k _ = k |

usage: |
Prelude> const 12 "lucky" 12 |

type: |
cos :: Float -> Float |

description: |
the trigonometric cosine function, arguments are interpreted to be in radians. |

definition: |
defined internally. |

usage: |
Prelude> cos pi -1 Prelude> cos (pi/.2.0) 6.12303e-017 |

type: |
div :: Int -> Int -> Int |

description: |
computes the integer division of its integral arguments. |

definition: |
defined internally. |

usage: |
Prelude> 16 `div` 9 1 Prelude> (-12) `div` 5 -3 |

notes: |
`div` is integer division such that the result is truncated towards negative infinity. |

type: |
drop :: Int -> [a] -> [a] |

description: |
applied to a number and a list, returns the list with the specified number of elements removed from the front of the list. If the list has less than the required number of elements then it returns []. |

definition: |
drop n xs | n <= 0 = xs drop _ [] = [] drop n (_:xs) = drop (n-1) xs |

usage: |
Prelude> drop 3 [1..10] [4, 5, 6, 7, 8, 9, 10] Prelude> drop 4 "abc" "" |

type: |
dropWhile :: (a -> Bool) -> [a] -> [a] |

description: |
applied to a predicate and a list, removes elements from the front of the list while the predicate is satisfied. |

definition: |
dropWhile p [] = [] dropWhile p (x:xs) | p x = dropWhile p xs | otherwise = (x:xs) |

usage: |
Prelude> dropWhile (< 5) [1..10] [5, 6, 7, 8, 9, 10] |

type: |
elemBy :: (a -> a -> Bool) -> a -> [a] -> Bool |

description: |
applied to a comparison function, a value and a list returns True if the value is in the list and False otherwise. The elements of the list must be of the same type as the value. |

definition: |
elemBy _ _ [] = False elemBy eq x (y:ys) | x `eq` y = True | otherwise = elemBy eq x ys |

usage: |
Prelude> elemBy (==) 5 [1..10] True Prelude> elemBy eqString "rat" ["fat", "cat"] False |

type: |
eqBool :: Bool -> Bool -> Bool |

description: |
is True if its first argument is equal to its second argument, and False otherwise. |

definition: |
eqBool True True = True eqBool False False = True eqBool _ _ = False |

usage: |
Prelude> eqBool True False False |

see also: |
eqBool, eqChar, eqList, eqString, (==), (==.) |

type: |
eqChar :: Char -> Char -> Bool |

description: |
is True if its first argument is equal to its second argument, and False otherwise. |

definition: |
eqChar c1 c2 = case ordChar c1 c2 of EQ -> True _ -> False |

usage: |
Prelude> filter (eqChar 'a') "banana" "aaa;" Prelude> elemBy eqChar 'x' "yada" False |

see also: |
eqBool, eqChar, eqList, eqString, (==), (==.) |

type: |
eqList :: (a -> a -> Bool) -> [a] -> [a] -> Bool |

description: |
is True if the first list is equal to the second list, and False otherwise. Elements are compared using the function passed as first argument. |

definition: |
eqList _ [] [] = True eqList eqElem (x:xs) (y:ys) = x `eqElem` y && eqList eqElem xs ys eqList _ _ _ = False |

usage: |
Prelude> eqList (==) [1,2,3] [1,2,4] False Prelude> eqList eqChar "abc" "abc" True |

see also: |
eqBool, eqChar, eqList, eqString, (==), (==.) |

type: |
eqString :: String -> String -> Bool |

description: |
is True if its first argument is equal to its second argument, and False otherwise. |

definition: |
eqString s1 s2 = case ordString s1 s2 of EQ -> True _ -> False |

usage: |
Prelude> eqString "Abc" "abc" False Prelude> eqString "abc" "abc" True |

see also: |
eqBool, eqChar, eqList, eqString, (==), (==.) |

type: |
error :: String -> a |

description: |
applied to a string creates an error value with an associated message. Error values are equivalent to the undefined value (undefined), any attempt to access the value causes the program to terminate and print the string as a diagnostic. |

definition: |
defined internally. |

usage: |
error "this is an error message" |

type: |
even :: Int -> Bool |

description: |
applied to an integral argument, returns True if the argument is even, and False otherwise. |

definition: |
even n = n `rem` 2 == 0 |

usage: |
Prelude> even 2 True Prelude> even (11 * 3) False |

type: |
exp :: Float -> Float |

description: |
the exponential function (exp n is equivalent to e^{n}). |

definition: |
defined internally. |

usage: |
Prelude> exp 1.0 2.71828 |

type: |
filter :: (a -> Bool) -> [a] -> [a] |

description: |
applied to a predicate and a list, returns a list containing all the elements from the argument list that satisfy the predicate. |

definition: |
filter p xs = [k | k <- xs, p k] |

usage: |
Prelude> filter isDigit "fat123cat456" "123456" |

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

description: |
applied to a binary function, returns the same function with the order of the arguments reversed. |

definition: |
flip f x y = f y x |

usage: |
Prelude> flip (elemBy (==)) [1..10] 5 True |

type: |
floor :: Float -> Int |

description: |
returns the largest integer not greater than its argument. |

usage: |
Prelude> floor 3.8 3 Prelude> floor (-.3.8) -4 |

see also: |
ceiling |

type: |
foldl :: (a -> b -> a) -> a -> [b] -> a |

description: |
folds up a list, using a given binary operator and a given start value, in a left associative manner. foldl op r [a, b, c] → ((r `op` a) `op` b) `op` c |

definition: |
foldl f z [] = z foldl f z (x:xs) = foldl f (f z x) xs |

usage: |
Prelude> foldl (+) 0 [1..10] 55 Prelude> foldl (flip (:)) [] [1..10] [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] |

type: |
foldl1 :: (a -> a -> a) -> [a] -> a |

description: |
folds left over non--empty lists. |

definition: |
foldl1 f (x:xs) = foldl f x xs |

usage: |
Prelude> foldl1 max [1, 10, 5, 2, -1] 10 |

type: |
foldr :: (a -> b -> b) -> b -> [a] -> b |

description: |
folds up a list, using a given binary operator and a given start value, in a right associative manner. foldr op r [a, b, c] → a `op` (b `op` (c `op` r)) |

definition: |
foldr f z [] = z foldr f z (x:xs) = f x (foldr f z xs) |

usage: |
Prelude> foldr (++) [] ["con", "cat", "en", "ate"] "concatenate" |

type: |
foldr1 :: (a -> a -> a) -> [a] -> a |

description: |
folds right over non--empty lists. |

definition: |
foldr1 f [x] = x foldr1 f (x:xs) = f x (foldr1 f xs) |

usage: |
Prelude> foldr1 (*) [1..10] 3628800 |

type: |
fromInt :: Int -> Float |

description: |
Converts from an Int to a Float |

usage: |
Prelude> fromInt 3 +. 4.1 7.1 |

type: |
fst :: (a, b) -> a |

description: |
returns the first element of a two element tuple. |

definition: |
fst (x, _) = x |

usage: |
Prelude> fst ("harry", 3) "harry" |

type: |
gcd :: Int -> Int -> Int |

description: |
returns the greatest common divisor between its two integral arguments. |

definition: |
gcd 0 0 = error "Prelude.gcd: gcd 0 0 is undefined" gcd x y = gcd' (abs x) (abs y) where gcd' x 0 = x gcd' x y = gcd' y (x `rem` y) |

usage: |
Prelude> gcd 2 10 2 Prelude> gcd (-7) 13 1 |

type: |
head :: [a] -> a |

description: |
returns the first element of a non--empty list. If applied to an empty list an error results. |

definition: |
head (x:_) = x |

usage: |
Prelude> head [1..10] 1 Prelude> head ["this", "and", "that"] "this" |

type: |
id :: a -> a |

description: |
the identity function, returns the value of its argument. |

definition: |
id x = x |

usage: |
Prelude> id 12 12 Prelude> id (id "fred") "fred" Prelude> eqList (==) (map id [1..10]) [1..10] True |

type: |
init :: [a] -> [a] |

description: |
returns all but the last element of its argument list. The argument list must have at least one element. If init is applied to an empty list an error occurs. |

definition: |
init [x] = [] init (x:xs) = x : init xs |

usage: |
Prelude> init [1..10] [1, 2, 3, 4, 5, 6, 7, 8, 9] |

type: |
isAlpha :: Char -> Bool |

description: |
applied to a character argument, returns True if the character is alphabetic, and False otherwise. |

definition: |
isAlpha c = isUpper c || isLower c |

usage: |
Prelude> isAlpha 'a' True Prelude> isAlpha '1' False |

type: |
isDigit :: Char -> Bool |

description: |
applied to a character argument, returns True if the character is a numeral, and False otherwise. |

definition: |
isDigit c = c >= '0' && c <= '9' |

usage: |
Prelude> isDigit '1' True Prelude> isDigit 'a' False |

type: |
isLower :: Char -> Bool |

description: |
applied to a character argument, returns True if the character is a lower case alphabetic, and False otherwise. |

definition: |
isLower c = c >= 'a' && c <= 'z' |

usage: |
Prelude> isLower 'a' True Prelude> isLower 'A' False Prelude> isLower '1' False |

type: |
isSpace :: Char -> Bool |

description: |
returns True if its character argument is a whitespace character and False otherwise. |

definition: |
isSpace c = c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v' |

usage: |
Prelude> dropWhile isSpace " \nhello \n" "hello \n" |

type: |
isUpper :: Char -> Bool |

description: |
applied to a character argument, returns True if the character is an upper case alphabetic, and False otherwise. |

definition: |
isUpper c = c >= 'A' && c <= 'Z' |

usage: |
Prelude> isUpper 'A' True Prelude> isUpper 'a' False Prelude> isUpper '1' False |

type: |
iterate :: (a -> a) -> a -> [a] |

description: |
iterate f x returns the infinite list [x,f x,f (f x),...]. |

definition: |
iterate f x = x : iterate f (f x) |

usage: |
Prelude> iterate (+1) 1 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ..... |

type: |
last :: [a] -> a |

description: |
applied to a non--empty list, returns the last element of the list. |

definition: |
last [x] = x last (_:xs) = last xs |

usage: |
Prelude> last [1..10] 10 |

type: |
lcm :: Int -> Int -> Int |

description: |
returns the least common multiple of its two integral arguments. |

definition: |
lcm _ 0 = 0 lcm 0 _ = 0 lcm x y = abs ((x `quot` gcd x y) * y) |

usage: |
Prelude> lcm 2 10 10 Prelude> lcm 2 11 22 |

type: |
length :: [a] -> Int |

description: |
returns the number of elements in a finite list. |

definition: |
length [] = 0 length (x:xs) = 1 + length xs |

usage: |
Prelude> length [1..10] 10 |

type: |
lines :: String -> [String] |

description: |
applied to a list of characters containing newlines, returns a list of lists by breaking the original list into lines using the newline character as a delimiter. The newline characters are removed from the result. |

usage: |
Prelude> lines "hello world\nit's me,\neric\n" ["hello world", "it's me,", "eric"] |

type: |
log :: Float -> Float |

description: |
returns the natural logarithm of its argument. |

definition: |
defined internally. |

usage: |
Prelude> log 1.0 0 Prelude> log 3.2 1.16315 |

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

description: |
given a function, and a list of any type, returns a list where each element is the result of applying the function to the corresponding element in the input list. |

definition: |
map f xs = [f x | x <- xs] |

usage: |
Prelude> map sqrt [1.0,2.0,3.0,4.0,5.0] [1,1.41421,1.73205,2,2.23607] |

type: |
max :: Int -> Int -> Int |

description: |
applied to two integers, returns the maximum of the two elements. |

definition: |
max :: Int -> Int -> Int max x y = if x < y then y else x |

usage: |
Prelude> max 1 2 2 |

type: |
maximum :: [Int] -> Int |

description: |
applied to a non--empty list of integers, returns the maximum element of the list. |

definition: |
maximum xs = foldl1 max xs |

usage: |
Prelude> maximum [-10, 0 , 5, 22, 13] 22 |

type: |
min :: Int -> Int -> Int |

description: |
applied to two integers, returns the minimum of the two. |

definition: |
min x y | x <= y = x | otherwise = y |

usage: |
Prelude> min 1 2 1 |

type: |
minimum :: [Int] -> Int |

description: |
applied to a non--empty list of integers, returns the minimum element of the list. |

definition: |
minimum xs = foldl1 min xs |

usage: |
Prelude> minimum [-10, 0 , 5, 22, 13] -10 |

type: |
mod :: Int -> Int -> Int |

description: |
returns the modulus of its two arguments. |

definition: |
defined internally. |

usage: |
Prelude> 16 `mod` 9 7 |

type: |
not :: Bool -> Bool |

description: |
returns the logical negation of its boolean argument. |

definition: |
not True = False not False = True |

usage: |
Prelude> not (3 == 4) True Prelude> not (10 > 2) False |

type: |
notElemBy :: (a -> a -> Bool) -> a -> [a] -> Bool |

description: |
returns True if its first argument is not an element of the list as its second argument. |

usage: |
Prelude> notElemBy (==) 3 [1,2,3] False Prelude> notElemBy (==) 4 [1,2,3] True |

type: |
null :: [a] -> Bool |

description: |
returns True if its argument is the empty list ([]) and False otherwise. |

definition: |
null [] = True null (_:_) = False |

usage: |
Prelude> null [] True Prelude> null (take 3 [1..10]) False |

type: |
odd :: Int -> Bool |

description: |
applied to an integral argument, returns True if the argument is odd, and False otherwise. |

definition: |
odd = not . even |

usage: |
Prelude> odd 1 True Prelude> odd (2 * 12) False |

type: |
or :: [Bool] -> Bool |

description: |
applied to a list of boolean values, returns their logical disjunction (see also `and'). |

definition: |
or xs = foldr (||) False xs |

usage: |
Prelude> or [False, False, True, False] True Prelude> or [False, False, False, False] False Prelude> or [] False |

type: |
ord :: Char -> Int |

description: |
applied to a character, returns its ascii code as an integer. |

definition: |
defined internally. |

usage: |
Prelude> ord 'A' 65 Prelude> (chr (ord 'A')) `eqChar` 'A' True |

see also: |
chr |

type: |
ordChar :: Char -> Char -> Ordering |

description: |
returns LT if the first argument is less than the second argument, GT if greater, EQ if equal |

definition: |
ordChar c1 c2 = ordInt (ord c1) (ord c2) |

usage: |
Prelude> ordChar 'a' 'b' LT List> sortBy ordChar "Helium is cool" " Hceiillmoosu" |

see also: |
ordChar, ordList, ordString, ordInt, ordFloat |

type: |
ordFloat :: Float -> Float -> Ordering |

description: |
returns LT if the first argument is less than the second argument, GT if greater, EQ if equal |

definition: |
ordFloat x y | x <. y = LT | x ==. y = EQ | otherwise = GT |

usage: |
Prelude> ordFloat 3.0 2.5 GT List> sortBy ordFloat [10.0, -.2.0, 2.5, 0.0, 2.6] [-2,0,2.5,2.6,10] |

see also: |
ordChar, ordList, ordString, ordInt, ordFloat |

type: |
ordInt :: Int -> Int -> Ordering |

description: |
returns LT if the first argument is less than the second argument, GT if greater, EQ if equal |

definition: |
ordInt x y | x < y = LT | x == y = EQ | otherwise = GT |

usage: |
Prelude> ordInt 3 3 EQ List> sortBy ordInt [10, -2, 3, 0, 4] [(-2),0,3,4,10] |

see also: |
ordChar, ordList, ordString, ordInt, ordFloat |

type: |
ordList :: (a -> a -> Ordering) -> [a] -> [a] -> Ordering |

description: |
returns LT if the first argument is less than the second argument, GT if greater, EQ if equal |

definition: |
ordList _ [] (_:_) = LT ordList _ [] [] = EQ ordList _ (_:_) [] = GT ordList ordElem (x:xs) (y:ys) = case ordElem x y of GT -> GT LT -> LT EQ -> ordList ordElem xs ys |

usage: |
Prelude> ordList ordInt [1,2,3] [1,2,4] LT List> sortBy (ordList ordInt) [[1,2],[], [1,0]] [[],[1,0],[1,2]] |

see also: |
ordChar, ordList, ordString, ordInt, ordFloat |

type: |
ordString :: String -> String -> Ordering |

description: |
returns LT if the first argument is less than the second argument, GT if greater, EQ if equal |

definition: |
ordString = ordList ordChar |

usage: |
Prelude> ordString "Abc" "abc" LT List> sortBy ordString ["helium", "is", "cool" ] ["cool","helium","is"] |

see also: |
ordChar, ordList, ordString, ordInt, ordFloat |

type: |
pi :: Float |

description: |
the ratio of the circumference of a circle to its diameter. |

definition: |
defined internally. |

usage: |
Prelude> pi 3.14159 Prelude> cos pi -1 |

type: |
putStr :: String -> IO () |

description: |
takes a string as an argument and returns an I/O action as a result. A side-effect of applying putStr is that it causes its argument string to be printed to the screen. |

definition: |
defined internally. |

usage: |
Prelude> putStr "Hello World\nI'm here!" Hello World I'm here! |

type: |
product :: [Int] -> Int |

description: |
applied to a list of numbers, returns their product. |

definition: |
product xs = foldl (*) 1 xs |

usage: |
Prelude> product [1..10] 3628800 |

type: |
quot :: Int -> Int -> Int |

description: |
returns the quotient after dividing the its first integral argument by its second integral argument. |

definition: |
defined internally. |

usage: |
Prelude> 16 `quot` 8 2 Prelude> quot 16 9 1 |

type: |
readInt :: String -> Int |

description: |
converts a String to an integer |

usage: |
Prelude> readInt "-123" + 3 (-120) |

type: |
rem :: Int -> Int -> Int |

description: |
returns the remainder after dividing its first integral argument by its second integral argument. |

definition: |
defined internally. |

usage: |
Prelude> 16 `rem` 8 0 Prelude> rem 16 9 7 |

notes: |
The following equality holds: (x `quot` y)*y + (x `rem` y) == x |

type: |
repeat :: a -> [a] |

description: |
given a value, returns an infinite list of elements the same as the value. |

definition: |
repeat x = xs where xs = x:xs |

usage: |
Prelude> repeat 12 [12, 12, 12, 12, 12, 12, 12, 12, 12, ... |

type: |
replicate :: Int -> a -> [a] |

description: |
given an integer (positive or zero) and a value, returns a list containing the specified number of instances of that value. |

definition: |
replicate n x = take n (repeat x) |

usage: |
Prelude> replicate 3 "apples" ["apples", "apples", "apples"] |

type: |
reverse :: [a] -> [a] |

description: |
applied to a finite list of any type, returns a list of the same elements in reverse order. |

definition: |
reverse = foldl (flip (:)) [] |

usage: |
Prelude> reverse [1..10] [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] |

type: |
round :: Float -> Int |

description: |
rounds its argument to the nearest integer. |

usage: |
Prelude> round 3.2 3 Prelude> round 3.5 4 Prelude> round (-.3.2) -3 |

type: |
showInt :: Int -> String |

description: |
returns the textual representation of an integer number |

usage: |
Prelude> showInt 42 "42" |

type: |
signum :: Int -> Int |

description: |
returns the sign (-1, 0 or 1) of a number. |

usage: |
Prelude> signum (-3) -1 |

type: |
signumFloat :: Float -> Int |

description: |
returns the sign (-1, 0 or 1) of a floating-point number. |

usage: |
Prelude> signumFloat 3.14 1 |

type: |
sin :: Float -> Float |

description: |
the trigonometric sine function, arguments are interpreted to be in radians. |

definition: |
defined internally. |

usage: |
Prelude> sin (pi/.2.0) 1 Prelude> ((sin pi)^.2) +. ((cos pi)^.2) 1 |

type: |
snd :: (a, b) -> b |

description: |
returns the second element of a two element tuple. |

definition: |
snd (_, y) = y |

usage: |
Prelude> snd ("harry", 3) 3 |

type: |
span :: (a -> Bool) -> [a] -> ([a],[a]) |

description: |
given a predicate and a list, splits the list into two lists (returned as a tuple) such that elements in the first list are taken from the head of the list while the predicate is satisfied, and elements in the second list are the remaining elements from the list once the predicate is not satisfied. |

definition: |
span p [] = ([],[]) span p xs@(x:xs') | p x = (x:ys, zs) | otherwise = ([],xs) where (ys,zs) = span p xs' |

usage: |
Prelude> span isDigit "123abc456" ("123", "abc456") |

type: |
splitAt :: Int -> [a] -> ([a],[a]) |

description: |
given an integer (positive or zero) and a list, splits the list into two lists (returned as a tuple) at the position corresponding to the given integer. If the integer is greater than the length of the list, it returns a tuple containing the entire list as its first element and the empty list as its second element. |

definition: |
splitAt n xs | n <= 0 = ([],xs) splitAt _ [] = ([],[]) splitAt n (x:xs) = (x:xs',xs'') where (xs',xs'') = splitAt (n-1) xs |

usage: |
Prelude> splitAt 3 [1..10] ([1, 2, 3], [4, 5, 6, 7, 8, 9, 10]) Prelude> splitAt 5 "abc" ("abc", "") |

type: |
sqrt :: Float -> Float |

description: |
returns the square root of a number. |

definition: |
sqrt x = x **. 0.5 |

usage: |
Prelude> sqrt 16.0 4 |

type: |
subtract :: Int -> Int -> Int |

description: |
subtracts its first argument from its second argument. |

definition: |
subtract = flip (-) |

usage: |
Prelude> subtract 7 10 3 |

type: |
sum :: [Int] -> Int |

description: |
computes the sum of a finite list of numbers. |

definition: |
sum xs = foldl (+) 0 xs |

usage: |
Prelude> sum [1..10] 55 |

type: |
tail :: [a] -> [a] |

description: |
applied to a non--empty list, returns the list without its first element. |

definition: |
tail (_:xs) = xs |

usage: |
Prelude> tail [1,2,3] [2,3] Prelude> tail "helium" "elium" |

type: |
take :: Int -> [a] -> [a] |

description: |
applied to an integer (positive or zero) and a list, returns the specified number of elements from the front of the list. If the list has less than the required number of elements, take returns the entire list. |

definition: |
take n _ | n <= 0 = [] take _ [] = [] take n (x:xs) = x : take (n-1) xs |

usage: |
Prelude> take 4 "goodbye" "good" Prelude> take 10 [1,2,3] [1,2,3] |

type: |
takeWhile :: (a -> Bool) -> [a] -> [a] |

description: |
applied to a predicate and a list, returns a list containing elements from the front of the list while the predicate is satisfied. |

definition: |
takeWhile p [] = [] takeWhile p (x:xs) | p x = x : takeWhile p xs | otherwise = [] |

usage: |
Prelude> takeWhile (<5) [1, 2, 3, 10, 4, 2] [1, 2, 3] |

type: |
tan :: Float -> Float |

description: |
the trigonometric function tan, arguments are interpreted to be in radians. |

definition: |
defined internally. |

usage: |
Prelude> tan (pi/.4.0) 1.0 |

type: |
toLower :: Char -> Char |

description: |
converts an uppercase alphabetic character to a lowercase alphabetic character. If this function is applied to an argument which is not uppercase the result will be the same as the argument unchanged. |

definition: |
toLower c | isUpper c = chr ( ord c - ord 'A' + ord 'a' ) | otherwise = c |

usage: |
Prelude> toLower 'A' 'a' Prelude> toLower '3' '3' |

type: |
toUpper :: Char -> Char |

description: |
converts a lowercase alphabetic character to an uppercase alphabetic character. If this function is applied to an argument which is not lowercase the result will be the same as the argument unchanged. |

definition: |
toUpper c | isLower c = chr ( ord c - ord 'a' + ord 'A' ) | otherwise = c |

usage: |
Prelude> toUpper 'a' 'A' Prelude> toUpper '3' '3' |

type: |
truncate :: Float -> Int |

description: |
drops the fractional part of a floating point number, returning only the integral part. |

usage: |
Prelude> truncate 3.2 3 Prelude> truncate (-.3.2) (-3) |

type: |
undefined :: a |

description: |
an undefined value. It is a member of every type. |

definition: |
undefined | False = undefined |

type: |
unlines :: [String] -> String |

description: |
converts a list of strings into a single string, placing a newline character between each of them. It is the converse of the function lines. |

definition: |
unlines [] = [] unlines (l:ls) = l ++ '\n' : unlines ls |

usage: |
Prelude> unlines ["helium","is","cool"] "helium\nis\ncool\n" |

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

description: |
given a predicate, a unary function and a value, it recursively re--applies the function to the value until the predicate is satisfied. If the predicate is never satisfied until will not terminate. |

definition: |
until p f x | p x = x | otheriwise = until p f (f x) |

usage: |
Prelude> until (> 1000) (*2) 1 1024 |

type: |
unwords :: [String] -> String |

description: |
concatenates a list of strings into a single string, placing a single space between each of them. |

definition: |
unwords [] = "" unwords [w] = w unwords (w:ws) = w ++ ' ' : unwords ws |

usage: |
Prelude> unwords ["the", "quick", "brown", "fox"] "the quick brown fox" |

type: |
words :: String -> [String] |

description: |
breaks its argument string into a list of words such that each word is delimited by one or more whitespace characters. |

definition: |
words s = case dropWhile isSpace s of "" -> [] s' -> w : words s'' where w,s'' :: String (w,s'') = break isSpace s' |

usage: |
Prelude> words "the quick brown\n\nfox" ["the", "quick", "brown", "fox"] |

type: |
zip :: [a] -> [b] -> [(a,b)] |

description: |
applied to two lists, returns a list of pairs which are formed by tupling together corresponding elements of the given lists. If the two lists are of different length, the length of the resulting list is that of the shortest. |

definition: |
zip xs ys = zipWith pair xs ys where pair x y = (x, y) |

usage: |
Prelude> zip [1..6] "abcd" [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')] |

type: |
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] |

description: |
applied to a binary function and two lists, returns a list containing elements formed be applying the function to corresponding elements in the lists. |

definition: |
zipWith z (a:as) (b:bs) = z a b : zipWith z as bs zipWith _ _ _ = [] |

usage: |
Prelude> zipWith (+) [1..5] [6..10] [7, 9, 11, 13, 15] |

type: |
(&&) :: Bool -> Bool -> Bool |

description: |
returns the logical conjunction of its two boolean arguments. |

usage: |
Prelude> True && True True Prelude> (3 < 4) && (4 < 5) && False False |

type: |
(||) :: Bool -> Bool -> Bool |

description: |
returns the logical disjunction of its two boolean arguments. |

usage: |
Prelude> True || False True Prelude> (3 < 4) || (4 > 5) || False True |

type: |
(!!) :: [a] -> Int -> a |

description: |
given a list and a number, returns the element of the list whose position is the same as the number. |

usage: |
Prelude> [1..10] !! 0 1 Prelude> "a string" !! 3 't' |

notes: |
the valid subscripts for a list l are: 0 .. (length l) - 1. Therefore, negative subscripts are not allowed, nor are subscripts greater than one less than the length of the list argument. Subscripts out of this range will result in a program error. |

type: |
(:) :: a -> [a] -> [a] |

description: |
prefixes an element onto the front of a list. |

usage: |
Prelude> 1:[2,3] [1,2,3] Prelude> True:[] [True] Prelude> 'h':"elium" "helium" |

type: |
(++) :: [a] -> [a] -> [a] |

description: |
appends its second list argument onto the end of its first list argument. |

usage: |
Prelude> [1,2,3] ++ [4,5,6] [1,2,3,4,5,6] Prelude> "foo " ++ "was" ++ " here" "foo was here" |

type: |
(.) :: (b -> c) -> (a -> b) -> a -> c |

description: |
composes two functions into a single function. |

usage: |
Prelude> (sqrt . fromInt . sum ) [1,2,3,4,5] 3.87298 |

notes: |
(f.g.h) x is equivalent to f (g (h x)). |

type: |
(**.) :: Float -> Float -> Float |

description: |
raises its first argument to the power of its second argument. |

usage: |
Prelude> 3.2**.pi 38.6345 |

type: |
(^) :: Int -> Int -> Int |

description: |
raises its first argument to the power of its second argument. |

usage: |
Prelude> 3^4 81 |

type: |
(*) :: Int -> Int -> Int |

description: |
returns the multiple of its two arguments. |

usage: |
Prelude> 6 * 2 12 |

type: |
(/) :: Int -> Int -> Int |

description: |
returns the result of dividing its first argument by its second. . |

usage: |
Prelude> 12 / 5 2 |

type: |
(+) :: Int -> Int -> Int |

description: |
returns the addition of its arguments. |

usage: |
Prelude> 3 + 4 7 |

type: |
(-) :: Int -> Int -> Int |

description: |
returns the substraction of its second argument from its first. |

usage: |
Prelude> 4 - 3 1 Prelude> 4 - (-3) 7 |

type: |
(/=) :: Int -> Int -> Bool |

description: |
is True if its first argument is not equal to its second argument, and False otherwise. |

usage: |
Prelude> 3 /= 4 True |

type: |
(==) :: Int -> Int -> Bool |

description: |
is True if its first argument is equal to its second argument, and False otherwise. |

usage: |
Prelude> 3 == 4 False |

see also: |
eqBool, eqChar, eqList, eqString, (==), (==.) |

type: |
(<) :: Int -> Int -> Bool |

description: |
returns True if its first argument is strictly less than its second argument, and False otherwise. |

usage: |
Prelude> 1 < 2 True |

type: |
(<=) :: Int -> Int -> Bool |

description: |
returns True if its first argument is less than or equal to its second argument, and False otherwise. |

usage: |
Prelude> 3 <= 4 True Prelude> 4 <= 4 True Prelude> 5 <= 4 False |

type: |
(>) :: Int -> Int -> Bool |

description: |
returns True if its first argument is strictly greater than its second argument, and False otherwise. . |

usage: |
Prelude> 2 > 1 True |

type: |
(>=) :: Int -> Int -> Bool |

description: |
returns True if its first argument is greater than or equal to its second argument, and False otherwise. |

usage: |
Prelude> 4 >= 3 True Prelude> 4 >= 4 True Prelude> 4 >= 5 False |

type: |
(*.) :: Float -> Float -> Float |

description: |
returns the multiple of its two arguments. |

usage: |
Prelude> 6.0 * 2.5 15 |

type: |
(/.) :: Float -> Float -> Float |

description: |
returns the result of dividing its first argument by its second. |

usage: |
Prelude> 12.0 /. 5.0 2.4 |

type: |
(+.) :: Float -> Float -> Float |

description: |
returns the addition of its arguments. |

usage: |
Prelude> 3.0 +. 4.5 7.5 |

type: |
(-.) :: Float -> Float -> Float |

description: |
returns the substraction of its second argument from its first. |

usage: |
Prelude> 4.0 -. 3.0 1 Prelude> 4.5 -. (-.3.0) 7.5 |

type: |
(^.) :: Float -> Int -> Float |

description: |
raises its first argument to the power of its second argument. |

usage: |
Prelude> 2.5 ^. 3 15.625 |

type: |
(/=.) :: Float -> Float -> Bool |

description: |
is True if its first argument is not equal to its second argument, and False otherwise. |

usage: |
Prelude> 3.0 /=. 4.0 True |

type: |
(==.) :: Float -> Float -> Bool |

description: |
is True if its first argument is equal to its second argument, and False otherwise. |

usage: |
Prelude> 3.0 ==. 4.0 False |

see also: |
eqBool, eqChar, eqList, eqString, (==), (==.) |

type: |
(<.) :: Float -> Float -> Bool |

description: |
returns True if its first argument is strictly less than its second argument, and False otherwise. . |

usage: |
Prelude> 1.0 <. 2.0 True |

type: |
(<=.) :: Float -> Float -> Bool |

description: |
returns True if its first argument is less than or equal to its second argument, and False otherwise. |

usage: |
Prelude> 3.0 <=. 4.0 True Prelude> 4.0 <=. 4.0 True Prelude> 5.0 <=. 4.0 False |

type: |
(>.) :: Float -> Float -> Bool |

description: |
returns True if its first argument is strictly greater than its second argument, and False otherwise. . |

usage: |
Prelude> 2.0 >. 1.0 True |

type: |
(>=.) :: Float -> Float -> Bool |

description: |
returns True if its first argument is greater than or equal to its second argument, and False otherwise. |

usage: |
Prelude> 4.0 >=. 3.0 True Prelude> 4.0 >=. 4.0 True Prelude> 4.0 >=. 5.0 False |

Edit | Attach | Print version | History: r6 < r5 < r4 < r3 | Backlinks | View wiki text | Edit wiki text | More topic actions

Topic revision: r6 - 26 Jun 2008, JurriaanHage

Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

Ideas, requests, problems regarding UUCS? Send feedback

Ideas, requests, problems regarding UUCS? Send feedback