SML Flashcards

1
Q

(T/F) In ML, programs are functions.

A

True

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

(T/F) In ML, running a program is evaluating an expression.

A

True

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

Do pure functional programming languages have assignment statements?

A

No

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

In ML, do functions have types?

A

Yes

Primitive Type:

int, real, char, string, and bool.

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

(T/F) In ML, types are not inferred.

A

False

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

What is the type of the following function?

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

What is the type of the following function?

A

‘a is a type variable.

‘a list is a list of whatever type ‘a is therefore size is a polymorphic function.

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

What is a polymorphic function?

A

A funciton that works with many different types.

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

In this example, what type does the plus sign default to?

A

This function defaults to int.

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

What has to happen to override the type to a real value?

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

What are curried functions?

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

In ML, what is the purpose of the @ symbol?

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

Give an example of a tuple in SML:

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

Give an example of a list in SML:

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

What is the keyword that declares a new variable and binds it to a value?

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

Redefining Names:

A
17
Q

Declaring functions in SML:

A
18
Q

What keywords are used for recursive definitions?

A
19
Q

What does the Fun keyword do?

A
20
Q

Give an example of pattern matching:

A
21
Q

What is the type of

toString 1 = “one”


fun toString 0 = “zero”


| toString 2 = “two”;

A

val toString = fn: int -> string

22
Q

Pattern Matching Default Value:

A
23
Q

What is the type of

fun sumList [] = 0
| sumList (x :: xs) = x + sumList xs;

A

val sumList = fn : int list -> int

24
Q

What is the result of

fun sumList [] = 0
| sumList (x :: xs) = x + sumList xs;

if sumList [2,3,1]; is executed?

A

sumList [2,3,1];

= sumList (2::[3,1])
= 2 + sumList [3,1]
= 2 + sumList (3::[1])
= 2 + 3 + sumList (1::[])
= 2 + 3 + 1 + sumList []
= 2 + 3 + 1 + 0
= 6

val it = 6 :int

25
Q
A
26
Q

Results of executing the following definition:

A
27
Q
A
28
Q

A higher order function is a function that takes function as argument and/or returns a function as a result.

A
29
Q

What is the type of map?

A
30
Q

What is an alternative to a curry function?

A
31
Q

What is a benefit of curried functions?

A
32
Q

What is the type of the following curry function?

fun curry f x y = f (x,y);

A
33
Q
A