Typing and Programming with Functions Flashcards

1
Q

what is a type?

A

a collection of related values

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

what is ⊥?

A

“bottom” - non-terminating stuff

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

how is type defined in Haskell?

A

e :: t means e has type t

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

what is a tuple?

A

a sequence of values of different types, surrounded by brackets ().

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

what does an apostrophe mean in Haskell?

A

it signifies a curried function

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

what is a curried function? (give an example)

A

a function that takes arguments one at a time

add’ :: Int -> (Int -> Int)
add’ x y = x + y

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

what are polymorphic functions?

A

functions that’s types contain multiple variable types, e.g. length :: [a] -> Int

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

What does it mean for a function to be overloaded?

A

a polymorphic funtion is overloaded if its type contains at least 1 class constraint, e.g. sum :: Num a => [a] -> a

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

give an example of a conditional expression in Haskell

A

signum :: Int -> Int
signum n = if n < 0 then -1 else
if n==0 then 0 else 1

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

give an example of a guarded equation on Haskell

A

signum n | n < 0 = -1
| n == 0 = 0
| otherwise = 1

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

what does _ signify?

A

a wildcard pattern that matches any argument value

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

use _ to define True or False with ands

A

True && b = b

False && _ = False

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

how are patterns matched?

A

in order

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

how is disjunction symbolised in Haskell?

A

||

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

use || to define True or False

A

False || b = b

True || _ = True

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

what is special about list comprehension?

A

its unique to functional programming

17
Q

give an example of multiple generator comprehension

A

[(x, y) | x

18
Q

give an example of dependant generator comprehension

A

[(x, y) | x

19
Q

write a dependent generator list concatenator for 3 lists.

A

concat :: [[a]] -> a

concat xss = [x | xs

20
Q

give an example of using a guard in Haskell

A

[x | x

21
Q

write a function to find factors of a numer

A

factors :: Int -> [Int]

factors n = [x | x

22
Q

use factors to write a prime function to determine whether a number is a prime

A

prime :: Int -> Bool

prime n = factors n == [1, n]

23
Q

what does zip do?

A

maps 2 lists to a list of pairs of their corresponding elements

24
Q

what is the type of zip?

A

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