Save
Haskell
built-in functions
Save
Share
Learn
Content
Leaderboard
Learn
Created by
Dewey Duey
Visit profile
Cards (18)
List:
lst = [1,2,3,4,5] = 1:2:3:4:5:[]
head
lst = 1
tail
lst = [2,3,4,5]
init
lst = [1,2,3,4]
last
lst = 5
example code of
map
:
doSth :: (a -> b) -> [a] -> [b]
doSth f [] = []
doSth f (x:xs) = f x : doSth f xs
example code of
filter
:
doSth :: (a -> Bool) -> [a] -> [a]
doSth p [] = []
doSth p (x:xs)
| p x = x : doSth p xs
| otherwise = doSth p xs
example of code of
zip
:
doSth :: [a] -> [b] -> [(a,b)]
doSth _ [] = []
doSth [] _ = []
doSth (x:xs) (y:ys) = (x,y) : doSth xs ys
map
(+1) [1..5] = [2,3,4,5,6]
filter
even [1..5] = [2,4]
zip
[1,2] [3,4,5] = [(1,3),(2,4)]
zipWith
(+) [1,2] [3,4,5] = [4,6]
function that returns the first of a pair
fst
function that returns the second of a pair
snd
zip: combines
two list
to
list
of
pairs
unzip
: splits a list of pairs into two lists
filter
: take elements that satisfy the condition and discard the rest.
foldl
: apply binary operator from left to right, accumulating result as it goes along.
foldr
: apply binary operator from right to left, accumulating result as it goes along.
map
: applies function to
every element
of
list
and return
new list
with
modified values
Returns the lowest of two arguments
min
Returns the highest of two arguments
max