Haskell Types Flashcards

1
Q

(!!)

A

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

    • [1,2,3] !! 1 = 2
    • gets you the value at index
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

($)

A

($) :: (a -> b) -> a -> b

– elem 2 $ filter (> 2) [1,2,3,4]

– ([a] -> Bool) -> [a] -> Bool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

($!)

A

($!) :: (a -> b) -> a -> b

– “call by value”, “strict evaluation”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

(&&)

A

(&&) :: Bool -> Bool -> Bool

– 1 == 1 && True = True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

(||)

A

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

– 1 == 1 || False = True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

(*)

A

(*) :: (Num a) => a -> a -> a

– 2 * 3 = 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

(**)

A

(**) :: (Floating a) => a -> a -> a

– 2 ** 3 = 8.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

(+)

A

(+) :: (Num a) => a -> a -> a

– 2 + 3 = 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

(++)

A

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

– [2,3] ++ [1,4,5] = [2,3,1,4,5]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

(-)

A

(-) :: (Num a) => a -> a -> a

– 2 - 3 = -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

(.)

A

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

– (head . reverse) [1,2,3] = 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

(/)

A

(/) :: (Fractional a) => a -> a -> a

– 6 / 2 = 3.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

(/=)

A

(/=) :: (Eq a) => a -> a -> Bool

– 2 /= 2 = False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

(

A

( a -> a -> Bool

– 2 < 3 = True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

(<=)

A

(<=) :: (Ord a) => a -> a -> Bool

– 3 <= 3 = True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

(==)

A

(==) :: (Eq a) => a -> a -> Bool

– 2 == 3 = False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

(=

A

(=< (a -> m b) -> m a -> m b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

(>)

A

(>) :: (Ord a) => a -> a -> Bool

– 2 > 3 = False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

(>=)

A

(>=) :: (Ord a) => a -> a -> Bool

– 3 >= 3 = True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

(»)

A

(») :: Monad m => m a -> m b -> m b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

(»=)

A

(»=) :: Monad m => m a -> (a -> m b) -> m b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

(^)

A

(^) :: (Num a, Integral b) => a -> b -> a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

(^^)

A

(^^) :: (Integral b, Fractional a) => a -> b -> a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

abs

A

abs :: (Num a) => a -> a

– abs (-42) = 42

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
all
all :: (a -> Bool) -> [a] -> Bool -- all even [2,4] = True
26
and
and :: [Bool] -> Bool - - and [True, True] = True - - and [True, True, False] = False
27
any
any :: Foldable t => (a -> Bool -> t a -> Bool -- any even [2,3] = True
28
break
break :: (a -> Bool) -> [a] -> ([a], [a]) -- break even [1,3,4,8,1] = ([1,3], [4,8,1])
29
ceiling
ceiling :: (Integral b, RealFrac a) => a -> b -- ceiling 2.7 = 3
30
compare
compare :: Ord a => a -> a -> Ordering
31
concat
concat :: Foldable t => t [a] -> [a] -- concat [[1,2],[3]] = [1,2,3]
32
concatMap
concatMap :: Foldable t => (a -> [b]) -> t a -> [b] -- concatMap ( \x -> [(x,2*x)] ) [2,3] = [(2,4),(3,6)]
33
curry
curry :: ((a,b) -> c) -> a -> b -> c -- curry fst 1 4 = 1
34
div
div :: Integral a => a -> a -> a
35
divMod
divMod :: Integral a => a -> a -> (a, a) -- divMod 9 2
36
drop
drop :: Int -> [a] -> [a]
37
dropWhile
dropWhile :: (a -> Bool) -> [a] -> [a]
38
elem
elem :: (Eq a, Foldable t) => a -> t a -> Bool
39
enumFrom
enumFrom :: Enum a => a -> [a] -- take 4 $ enumFrom 3 = [3,4,5,6]
40
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)
41
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
42
take 4 $ enumFromThen 3 5
take 4 $ enumFromThen 3 5 :: (Num a, Enum a) => [a] -- take 4 $ enumFromThen 3 5 = [3,5,7,9]
43
error
error :: [Char] -> a
44
even
even :: Integral a => a -> Bool
45
exp
exp :: Floating a => a -> a
46
filter
filter :: (a -> Bool) -> [a] -> [a]
47
filter (< 3)
filter (< 3) :: (Num a, Ord a) = > [a] -> [a]
48
flip
flip :: (a -> b -> c) -> b -> a -> c
49
floor
floor :: (Integral b, RealFrac a) => a -> b
50
fmap
fmap :: Functor f => (a -> b) -> f a -> f b
51
foldl
foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
52
foldr
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
53
fromEnum
fromEnum :: Enum a => a -> Int -- fromEnum 'b' = 98
54
fromInteger
fromInteger :: Num a => Integer -> a
55
fromIntegral
fromIntegral :: (Num b, Integral a) => a -> b
56
fromRational
fromRational :: Fractional a => Rational -> a
57
fst
fst :: (a, b) -> a
58
gcd
gcd :: Integral a => a -> a -> a -- gcd 15 20 = 5
59
getLine
getLine :: IO String > getLine input: > hello output: > "hello"
60
head
head :: [a] -> a -- head [1,2,3] = 1
61
id
id :: a -> a
62
init
init :: [a] -> a -- init [1,2,3,4,5] = [1,2,3,4]
63
last
last :: [a] -> a -- last [1,2,3,4,5] = 5
64
lcm
lcm :: Integral a => a -> a -> - - lcm x y is the smallest positive integer that both x and y divide - - lcm 5 3 = 15
65
length
length :: Foldable t => t a -> Int
66
lines
lines :: String -> [String] - - line "break me\nup" = ["break me", "up] - - breaks up on \n
67
log
log :: Floating a => a -> a
68
logBase
logBase :: Floating a => a -> a -> a
69
lookup
lookup :: Eq a => a -> [(a, b)] -> Maybe b
70
map
map :: (a -> b) -> [a] -> [b]
71
max
max :: Ord a => a -> a -> a -- max 'b' 'a' = 'b'
72
maxBound
maxBound :: Bounded a => a
73
maximum
maximum :: (Ord a, Foldable t) => t a -> a -- maximum "maximum" = 'x'
74
maybe
maybe :: b -> (a -> b) -> Maybe a -> b
75
min
min :: Ord a => a -> a -> a
76
minBound
minBound :: Bounded a => a
77
minimum
minimum :: (Ord a, Foldable t) => t a -> a
78
mod
mod :: Integral a => a -> a -> a
79
negate
negate :: Num a => a -> a
80
not
not :: Bool -> Bool
81
notElem
notElem (Eq a, Foldable t) -> t a -> Bool
82
null
null :: Foldable t => t a -> Bool -- null [] = True
83
or
or :: Foldable t => t Bool -> Bool
84
otherwise
otherwise :: Bool
85
pi
pi :: Floating a => a
86
pred
pred :: Enum a => a -> a - - pred 'b' = 'a' - - pred 3 = 2
87
print
print :: Show a => a -> IO () > print "Hello" > "Hello"
88
product
product :: (Num a, Foldable t) => t a -> a
89
putStr
putStr :: String -> IO () -- same as putStrLn just without a \n after it
90
putStrLn
putStrLn :: String -> IO () > putStrLn "hello" > hello -- notice that it doens't have " " around hello like print does
91
quot
quot :: Integral a => a -> a -> a -- quot 8 3 = 2
92
quotRem
quotRem :: Integral a => a -> a -> (a, a) - - quotRem 8 3 = (2, 2) - - quotRem 4 2 = (2, 0)
93
read
read :: Read a => String -> a
94
rem
rem :: Integral a => a -> a -> a - - rem 8 3 = 2 - - rem 4 2 = 0
95
repeat
repeat :: a -> [a] -- take 3 $ repeat 5 = [5,5,5]
96
replicate
replicate :: Int -> a -> [a] - - replicate 3 5 = [5, 5, 5] - - similar to take 3 $ repeat 5, just shorter and simpler
97
return
return :: Monad m => a -> m a
98
reverse
reverse :: [a] -> [a]
99
round
round :: (Integral b, RealFrac a) => a -> b - - round 2.5 = 2 - - round 2.399 = 2 - - round (-1.2) = (-1) - - round 2.9 = 3
100
show
show :: Show a => a -> String - - show "hello" = "\"hello\"" - - show 4 = "4" - - show 'a' = "'a'"
101
snd
snd :: (a, b) -> b
102
span
span :: (a -> Bool) -> [a] -> ([a], [a])
103
splitAt
splitAt :: Int -> [a] -> ([a], [a]) -- splitAt 3 [1,2,3,4] = ([1,2,3], [4])
104
sqrt
sqrt :: Floating a => a -> a
105
subtract
subtract :: Num a => a -> a -> a
106
succ
succ :: Enum a => a -> a
107
sum
sum :: (Num a, Foldable t) => t a -> a
108
tail
tail :: [a] -> [a] -- tail [1,2,3] = [2,3]
109
take
take :: Int -> [a] -> [a]
110
takeWhile
takeWhile :: (a -> Bool) -> [a] -> [a] - - takeWhile (> 0) [1,2,-3,4] = [1,2] - - takeWhile (> 0) [1,-2,3,4] = [1] -- stops taking and ignores the rest of list when hits first false
111
toEnum
toEnum :: Enum a => Int -> a
112
truncate
truncate :: (Integral b, RealFrac a) => a -> b - - truncate 2.9 = 2 - - truncate (-1.999) = -1
113
uncurry
uncurry :: (a -> b -> c) -> (a, b) -> c -- uncurry div (9,2) = 4
114
undefined
undefined :: a
115
unlines
unlines :: [String] -> String -- unlines ["ab", "cd"] = "ab\ncd\n"
116
until
until :: (a -> Bool) -> (a -> a) -> a -> a
117
unzip
unzip :: [(a, b)] -> ([a], [b]) - - unzip [(1,2,3), (4,5,6)] = error, can't match (a,b) with (Integer, Integer, Integer) - - unzip [(1,2), (4,5)] = ([1,4], [2,5]) - - unzip [(1,2), (4,5), (6,7), (0, -10)] = ([1,4,6,0], [2,5,7,-10])
118
unzip3
unzip3 :: [(a, b, c)] - > ([a], [b], [c]) -- unzip [(1,2,3), (4,5,6), (9,8,1)] = ([1,4,9], [2,5,8], [3,6,1])
119
words
words :: String -> [String] -- words "some words" = ["some", "words"]
120
zip
zip :: [a] -> [b] -> [(a, b)] -- zip [1,2,3] [4,5,6] = [(1,4), (2,5), (3,6)]
121
zip3
zip3 :: [a] -> [b] -> [c] -> [(a, b, c)] -- zip3 [1,2] [4,5] [9,8] = [(1,4,9), (2,5,8)]
122
zipWith
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
123
zipWith3
zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
124
(\x -> x)
(\x -> x) :: t -> t
125
(True:True)
Error
126
(:[]) 3
Num a => [a]
127
(:[]) [1,2,3]
Num t => [[t]]
128
filter ((==2) . length) [[1,2,3,4,5,6],[1,2]]
Num a => [[a]]
129
filter (length . (==2)) [[1,2,3,4,5,6],[1,2]]
Error
130
Just a
Maybe [Char]
131
Just []
Maybe [t]
132
Just 2
Num a => Maybe a
133
Just [1,2,3]
Num t => Maybe [t]
134
maybe []
(a -> [t]) -> Maybe a -> [t]
135
maybe 3
Num b => (a -> b) -> Maybe a -> b