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
Q

all

A

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

– all even [2,4] = True

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

and

A

and :: [Bool] -> Bool

    • and [True, True] = True
    • and [True, True, False] = False
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

any

A

any :: Foldable t => (a -> Bool -> t a -> Bool

– any even [2,3] = True

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

break

A

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

– break even [1,3,4,8,1] = ([1,3], [4,8,1])

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

ceiling

A

ceiling :: (Integral b, RealFrac a) => a -> b

– ceiling 2.7 = 3

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

compare

A

compare :: Ord a => a -> a -> Ordering

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

concat

A

concat :: Foldable t => t [a] -> [a]

– concat [[1,2],[3]] = [1,2,3]

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

concatMap

A

concatMap :: Foldable t => (a -> [b]) -> t a -> [b]

– concatMap ( \x -> [(x,2*x)] ) [2,3] = [(2,4),(3,6)]

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

curry

A

curry :: ((a,b) -> c) -> a -> b -> c

– curry fst 1 4 = 1

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

div

A

div :: Integral a => a -> a -> a

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

divMod

A

divMod :: Integral a => a -> a -> (a, a)

– divMod 9 2

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

drop

A

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

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

dropWhile

A

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

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

elem

A

elem :: (Eq a, Foldable t) => a -> t a -> Bool

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

enumFrom

A

enumFrom :: Enum a => a -> [a]

– take 4 $ enumFrom 3 = [3,4,5,6]

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

enumFromThen

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

enumFromThenTo

A

enumFromThenTo :: Enum a => a -> a -> a -> [a]

    • enumFromThenTo 3 5 9 = [3,5,7,9]
    • doesn’t need take because there’s an end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

take 4 $ enumFromThen 3 5

A

take 4 $ enumFromThen 3 5 :: (Num a, Enum a) => [a]

– take 4 $ enumFromThen 3 5 = [3,5,7,9]

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

error

A

error :: [Char] -> a

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

even

A

even :: Integral a => a -> Bool

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

exp

A

exp :: Floating a => a -> a

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

filter

A

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

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

filter (< 3)

A

filter (< 3) :: (Num a, Ord a) = > [a] -> [a]

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

flip

A

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

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

floor

A

floor :: (Integral b, RealFrac a) => a -> b

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

fmap

A

fmap :: Functor f => (a -> b) -> f a -> f b

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

foldl

A

foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b

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

foldr

A

foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b

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

fromEnum

A

fromEnum :: Enum a => a -> Int

– fromEnum ‘b’ = 98

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

fromInteger

A

fromInteger :: Num a => Integer -> a

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

fromIntegral

A

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

56
Q

fromRational

A

fromRational :: Fractional a => Rational -> a

57
Q

fst

A

fst :: (a, b) -> a

58
Q

gcd

A

gcd :: Integral a => a -> a -> a

– gcd 15 20 = 5

59
Q

getLine

A

getLine :: IO String

> getLine

input: > hello
output: > “hello”

60
Q

head

A

head :: [a] -> a

– head [1,2,3] = 1

61
Q

id

A

id :: a -> a

62
Q

init

A

init :: [a] -> a

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

63
Q

last

A

last :: [a] -> a

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

64
Q

lcm

A

lcm :: Integral a => a -> a ->

    • lcm x y is the smallest positive integer that both x and y divide
    • lcm 5 3 = 15
65
Q

length

A

length :: Foldable t => t a -> Int

66
Q

lines

A

lines :: String -> [String]

    • line “break me\nup” = [“break me”, “up]
    • breaks up on \n
67
Q

log

A

log :: Floating a => a -> a

68
Q

logBase

A

logBase :: Floating a => a -> a -> a

69
Q

lookup

A

lookup :: Eq a => a -> [(a, b)] -> Maybe b

70
Q

map

A

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

71
Q

max

A

max :: Ord a => a -> a -> a

– max ‘b’ ‘a’ = ‘b’

72
Q

maxBound

A

maxBound :: Bounded a => a

73
Q

maximum

A

maximum :: (Ord a, Foldable t) => t a -> a

– maximum “maximum” = ‘x’

74
Q

maybe

A

maybe :: b -> (a -> b) -> Maybe a -> b

75
Q

min

A

min :: Ord a => a -> a -> a

76
Q

minBound

A

minBound :: Bounded a => a

77
Q

minimum

A

minimum :: (Ord a, Foldable t) => t a -> a

78
Q

mod

A

mod :: Integral a => a -> a -> a

79
Q

negate

A

negate :: Num a => a -> a

80
Q

not

A

not :: Bool -> Bool

81
Q

notElem

A

notElem (Eq a, Foldable t) -> t a -> Bool

82
Q

null

A

null :: Foldable t => t a -> Bool

– null [] = True

83
Q

or

A

or :: Foldable t => t Bool -> Bool

84
Q

otherwise

A

otherwise :: Bool

85
Q

pi

A

pi :: Floating a => a

86
Q

pred

A

pred :: Enum a => a -> a

    • pred ‘b’ = ‘a’
    • pred 3 = 2
87
Q

print

A

print :: Show a => a -> IO ()

> print “Hello”
“Hello”

88
Q

product

A

product :: (Num a, Foldable t) => t a -> a

89
Q

putStr

A

putStr :: String -> IO ()

– same as putStrLn just without a \n after it

90
Q

putStrLn

A

putStrLn :: String -> IO ()

> putStrLn “hello”
hello

– notice that it doens’t have “ “ around hello like print does

91
Q

quot

A

quot :: Integral a => a -> a -> a

– quot 8 3 = 2

92
Q

quotRem

A

quotRem :: Integral a => a -> a -> (a, a)

    • quotRem 8 3 = (2, 2)
    • quotRem 4 2 = (2, 0)
93
Q

read

A

read :: Read a => String -> a

94
Q

rem

A

rem :: Integral a => a -> a -> a

    • rem 8 3 = 2
    • rem 4 2 = 0
95
Q

repeat

A

repeat :: a -> [a]

– take 3 $ repeat 5 = [5,5,5]

96
Q

replicate

A

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

    • replicate 3 5 = [5, 5, 5]
    • similar to take 3 $ repeat 5, just shorter and simpler
97
Q

return

A

return :: Monad m => a -> m a

98
Q

reverse

A

reverse :: [a] -> [a]

99
Q

round

A

round :: (Integral b, RealFrac a) => a -> b

    • round 2.5 = 2
    • round 2.399 = 2
    • round (-1.2) = (-1)
    • round 2.9 = 3
100
Q

show

A

show :: Show a => a -> String

    • show “hello” = “"hello"”
    • show 4 = “4”
    • show ‘a’ = “‘a’”
101
Q

snd

A

snd :: (a, b) -> b

102
Q

span

A

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

103
Q

splitAt

A

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

– splitAt 3 [1,2,3,4] = ([1,2,3], [4])

104
Q

sqrt

A

sqrt :: Floating a => a -> a

105
Q

subtract

A

subtract :: Num a => a -> a -> a

106
Q

succ

A

succ :: Enum a => a -> a

107
Q

sum

A

sum :: (Num a, Foldable t) => t a -> a

108
Q

tail

A

tail :: [a] -> [a]

– tail [1,2,3] = [2,3]

109
Q

take

A

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

110
Q

takeWhile

A

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
Q

toEnum

A

toEnum :: Enum a => Int -> a

112
Q

truncate

A

truncate :: (Integral b, RealFrac a) => a -> b

    • truncate 2.9 = 2
    • truncate (-1.999) = -1
113
Q

uncurry

A

uncurry :: (a -> b -> c) -> (a, b) -> c

– uncurry div (9,2) = 4

114
Q

undefined

A

undefined :: a

115
Q

unlines

A

unlines :: [String] -> String

– unlines [“ab”, “cd”] = “ab\ncd\n”

116
Q

until

A

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

117
Q

unzip

A

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
Q

unzip3

A

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
Q

words

A

words :: String -> [String]

– words “some words” = [“some”, “words”]

120
Q

zip

A

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

– zip [1,2,3] [4,5,6] = [(1,4), (2,5), (3,6)]

121
Q

zip3

A

zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]

– zip3 [1,2] [4,5] [9,8] = [(1,4,9), (2,5,8)]

122
Q

zipWith

A

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

123
Q

zipWith3

A

zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]

124
Q

(\x -> x)

A

(\x -> x) :: t -> t

125
Q

(True:True)

A

Error

126
Q

(:[]) 3

A

Num a => [a]

127
Q

(:[]) [1,2,3]

A

Num t => [[t]]

128
Q

filter ((==2) . length) [[1,2,3,4,5,6],[1,2]]

A

Num a => [[a]]

129
Q

filter (length . (==2)) [[1,2,3,4,5,6],[1,2]]

A

Error

130
Q

Just a

A

Maybe [Char]

131
Q

Just []

A

Maybe [t]

132
Q

Just 2

A

Num a => Maybe a

133
Q

Just [1,2,3]

A

Num t => Maybe [t]

134
Q

maybe []

A

(a -> [t]) -> Maybe a -> [t]

135
Q

maybe 3

A

Num b => (a -> b) -> Maybe a -> b