Functional language computation definition
What is mathematical functions?
Expressions are like this
What is statements in imperative languages?
State the type of this function:
let rec fact n =
if n = 0 then 1
else n * fact(n -1)
int -> int
Describe lists ( length and type)
Definition of First-class Function
State of functional language
What is immutable?
Every kind of expression has these two things
What are syntax (metavariable e to designate an arbitrary expression) and semantics (type checking rules and evaluation rules)
type of foo 4 2
let rec foo n m =
if n >= 9 || n < 0 then m
else n + m + 1
What is int?
Method to insert "a" into a list "list"
"a" :: list
What ML stands for
What is Meta Language?
Properties of functional language
What are higher level of abstraction, easier to develop robust software, immutable state, and easier to reason about software?
Definition of value
What is an expression that is final?
Ex: 34 is a value and 34 + 17 is an expression
The type of the list: [1.0;2.0;3.0;4.0]
float list
How would you view the third element of the list that is guaranteed to have 3 + elements
match lst with
a :: b :: c -> [c]
Course name of CMSC 330
Organization of Programming Languages
Properties of imperative languages?
To what value does this expression evaluate
if 22 < 0 then "butterfly" else 1
Has 2 different types, so get a type error
Correct use of if statements
if e1 then e2 else e3
e2 and e3 are the same type
Are lists immutable or mutable?
Immutable : there is no way to change an element of a list, instead build up new lists out of old.
Give an example of a function that has a polymorphic type ('a list -> 'a) and one with a int type (int list -> int)
let fst x y = x
let fst a b = a + b
Key features of ML
First-class functions, favors immutability, data types and pattern matching, type inference, parametric polymorphism
Role of "=" in n = 0
Infix function that takes two ints and returns a bool
n must be an int to type check
Can only be used between two equal signs
Type of following definition :
let f x = 1::[x]
int -> int list
_ is
What is a wildcard pattern?
Matches anything, doesn't add any bindings, useful to hold a place but discards the value
What is the difference between tuples and lists?
A tuple can have more than one type and you can add to a list.