Haskell Types Flashcards
(!!)
(!!) :: [a] -> Int -> a
- [1,2,3] !! 1 = 2
- gets you the value at index
($)
($) :: (a -> b) -> a -> b
– elem 2 $ filter (> 2) [1,2,3,4]
– ([a] -> Bool) -> [a] -> Bool
($!)
($!) :: (a -> b) -> a -> b
– “call by value”, “strict evaluation”
(&&)
(&&) :: Bool -> Bool -> Bool
– 1 == 1 && True = True
(||)
(||) :: Bool -> Bool -> Bool
– 1 == 1 || False = True
(*)
(*) :: (Num a) => a -> a -> a
– 2 * 3 = 6
(**)
(**) :: (Floating a) => a -> a -> a
– 2 ** 3 = 8.0
(+)
(+) :: (Num a) => a -> a -> a
– 2 + 3 = 5
(++)
(++) :: [a] -> [a] -> [a]
– [2,3] ++ [1,4,5] = [2,3,1,4,5]
(-)
(-) :: (Num a) => a -> a -> a
– 2 - 3 = -1
(.)
(.) :: (b -> c) -> (a -> b) -> c
– (head . reverse) [1,2,3] = 3
(/)
(/) :: (Fractional a) => a -> a -> a
– 6 / 2 = 3.0
(/=)
(/=) :: (Eq a) => a -> a -> Bool
– 2 /= 2 = False
(
( a -> a -> Bool
– 2 < 3 = True
(<=)
(<=) :: (Ord a) => a -> a -> Bool
– 3 <= 3 = True
(==)
(==) :: (Eq a) => a -> a -> Bool
– 2 == 3 = False
(=
(=< (a -> m b) -> m a -> m b
(>)
(>) :: (Ord a) => a -> a -> Bool
– 2 > 3 = False
(>=)
(>=) :: (Ord a) => a -> a -> Bool
– 3 >= 3 = True
(»)
(») :: Monad m => m a -> m b -> m b
(»=)
(»=) :: Monad m => m a -> (a -> m b) -> m b
(^)
(^) :: (Num a, Integral b) => a -> b -> a
(^^)
(^^) :: (Integral b, Fractional a) => a -> b -> a
abs
abs :: (Num a) => a -> a
– abs (-42) = 42
all
all :: (a -> Bool) -> [a] -> Bool
– all even [2,4] = True
and
and :: [Bool] -> Bool
- and [True, True] = True
- and [True, True, False] = False
any
any :: Foldable t => (a -> Bool -> t a -> Bool
– any even [2,3] = True
break
break :: (a -> Bool) -> [a] -> ([a], [a])
– break even [1,3,4,8,1] = ([1,3], [4,8,1])
ceiling
ceiling :: (Integral b, RealFrac a) => a -> b
– ceiling 2.7 = 3
compare
compare :: Ord a => a -> a -> Ordering
concat
concat :: Foldable t => t [a] -> [a]
– concat [[1,2],[3]] = [1,2,3]
concatMap
concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
– concatMap ( \x -> [(x,2*x)] ) [2,3] = [(2,4),(3,6)]
curry
curry :: ((a,b) -> c) -> a -> b -> c
– curry fst 1 4 = 1
div
div :: Integral a => a -> a -> a
divMod
divMod :: Integral a => a -> a -> (a, a)
– divMod 9 2
drop
drop :: Int -> [a] -> [a]
dropWhile
dropWhile :: (a -> Bool) -> [a] -> [a]
elem
elem :: (Eq a, Foldable t) => a -> t a -> Bool
enumFrom
enumFrom :: Enum a => a -> [a]
– take 4 $ enumFrom 3 = [3,4,5,6]
enumFromThen
enumFromThen :: Enum a => a -> a -> [a]
- take 4 $ enumFromThen 3 5 = [3,5,7,9]
- figures out how many to enum by (rather than just increasing by 1)
enumFromThenTo
enumFromThenTo :: Enum a => a -> a -> a -> [a]
- enumFromThenTo 3 5 9 = [3,5,7,9]
- doesn’t need take because there’s an end
take 4 $ enumFromThen 3 5
take 4 $ enumFromThen 3 5 :: (Num a, Enum a) => [a]
– take 4 $ enumFromThen 3 5 = [3,5,7,9]
error
error :: [Char] -> a
even
even :: Integral a => a -> Bool
exp
exp :: Floating a => a -> a
filter
filter :: (a -> Bool) -> [a] -> [a]
filter (< 3)
filter (< 3) :: (Num a, Ord a) = > [a] -> [a]
flip
flip :: (a -> b -> c) -> b -> a -> c
floor
floor :: (Integral b, RealFrac a) => a -> b
fmap
fmap :: Functor f => (a -> b) -> f a -> f b
foldl
foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
foldr
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
fromEnum
fromEnum :: Enum a => a -> Int
– fromEnum ‘b’ = 98
fromInteger
fromInteger :: Num a => Integer -> a