Haskell Flashcards

(32 cards)

1
Q

Dot operator type

A

(b -> c) -> (a -> b) -> a -> c

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

exOr x y =

A

(x || y) && not(x && y)

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

Offset between a lowercase character and its uppercase counterpart

A

32
ord ‘a’ = 97; ord ‘A’ = 65

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

Read and show

A

Read: convert from a string to a value
Show: Convert from a value to a string

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

C enumeration vs Java enumeration

A

C: Integers and enum types can be mixed freely
Java: Defines a new type

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

Switch case in Java, C, C++

A

Default is to fall through. Prevented by ‘break’

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

Switch case in Prolog, C#

A

Cannot fall through. permitted by ‘next’

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

Evaluate the inline conditional expression: (x % 2 == 0 ? “even” : “odd)

A

if (x % 2 == 0) {“even”}
else {“odd”}

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

What is an Ivalue in C++

A

An Ivalue is an expression that yields an object reference

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

T-square evolution algorithm

A
  1. Start with a square
  2. At each convex corner, place another square, centered at the corner, with half the side length of the previous square
  3. Repeat step 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

T-square evolution recursive parameters

A

Width decreased by 1/2, Step is decreased by 1, Fill the square

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

Functions used on tuples of size 2 (pairs)

A

‘fst’ to retrieve first element
‘snd’ to retrieve second element

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

Lists in Haskell vs. Arrays in C/C++/Java

A

Memory in arrays is contiguous;
Any element can be accessed in constant time

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

head :: [a] -> a

A

Returns the first element in a list

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

tail :: [a] -> [a]

A

Returns a list with all elements in a list except for the first element

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

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

A

Returns a list with the first n elements in a list

17
Q

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

A

Returns the list after removing its first n elements

18
Q

length :: [a] -> Int

A

Returns number of elements in a list

19
Q

: :: a -> [a] -> [a]

A

Add a single element to the front of a list

20
Q

++ :: [a] -> [a] -> [a]

A

Join two lists

21
Q

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

A

Returns the nth element of a list starting from 0

22
Q

reverse :: [a] -> [a]

A

Reverse the order of elements

23
Q

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

A

Take a pair of lists into a list of pairs

24
Q

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

A

Take a list of pair into a pair of lists

25
sum :: [Int]/[Float] -> Int/Float
Sum of a numeric list
26
(x:xs)
Splits a list into its head and tail; x is the head, xs is the tail
27
List Comprehension General form
[Expression involving var | var <- old list, conditions, ..., conditions]
28
What is 'var <- old list' called
Generator. iterates over the old list, multiple generators can be used
29
Higher order function
A function that takes one or more functions as a parameter and/or returns a function as its result
30
Map general form
map :: (a -> b) -> [a] -> [b]; function (a -> b) is applied to every element in [a] and the result is the new list [b]
31
General form of lambda function
\... ->
32
Filter function
First argument is a predicate (returns a boolean), second argument is a list