SML Flashcards
(T/F) In ML, programs are functions.
True
(T/F) In ML, running a program is evaluating an expression.
True
Do pure functional programming languages have assignment statements?
No
In ML, do functions have types?
Yes
Primitive Type:
int, real, char, string, and bool.
(T/F) In ML, types are not inferred.
False
What is the type of the following function?


What is the type of the following function?

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

What is a polymorphic function?
A funciton that works with many different types.

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

This function defaults to int.

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


What are curried functions?

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

Give an example of a tuple in SML:

Give an example of a list in SML:

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

Redefining Names:

Declaring functions in SML:

What keywords are used for recursive definitions?

What does the Fun keyword do?

Give an example of pattern matching:

What is the type of
toString 1 = “one”
fun toString 0 = “zero”
| toString 2 = “two”;
val toString = fn: int -> string
Pattern Matching Default Value:

What is the type of
fun sumList [] = 0
| sumList (x :: xs) = x + sumList xs;
val sumList = fn : int list -> int
What is the result of
fun sumList [] = 0
| sumList (x :: xs) = x + sumList xs;
if sumList [2,3,1]; is executed?
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


Results of executing the following definition:




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

What is the type of map?


What is an alternative to a curry function?

What is a benefit of curried functions?

What is the type of the following curry function?
fun curry f x y = f (x,y);
