Programming III Flashcards
What are the distinct type operators in the below function definition?
(,) , -> , [] , Maybe
What are the distinct data constructors in the below function definition?
Nothing , Just , []
Higher Order Function
A function that takes a function as an argument, or returns a function.
Example: all curried functions
Curried function
A function that returns a function
curry and uncurry
curry: takes function that takes a single argument, and returns that function so that it takes multiple arguments.
uncurry: takes function that takes multiple arguments, and returns that function so that it takes a single argument.
Polymorphic function
A function is polymorphic if its type definition contains one or more unconstrained type variable
zip function
Appends two lists together, combining values from the same index into a pair.
If one list is shorter, it truncates the longer list.
zip: [a] -> [b] -> [(a,b)]
Alpha equivalent
Two terms are alpha equivalent if one can be converted to the other by alpha conversion.
* λ x -> λ y -> x y z is alpha equivalent to:
λ x -> λ w -> x w z
* λ x -> λ y -> x y z is not alpha equivalent to:
λ x -> λ z -> x z z
Redex
Reducible expression:
an expression comprising a function applied to an argument expression.
Innermost redex
A redex containing no other redexes
Outermost redex
A redex not contained in any other redex
Innermost evaluation
Innermost redexes are evaluated first
Outermost evaluation
Outermost redexes are evaluated first
Leftmost evaluation
Start with the leftmost redex
Rightmost evaluation
Start with the rightmost redex
Haskell evaluation strategy
Outmost, leftmost evaluation
Call-by-Name
Call-by-Value reduction strategy
Leftmost, innermost reduction
Call-by-Name evalution strategy
Leftmost, outermost evaluation
Lambda calculus
Bound and Free variables
A variable is bound if given with a lambda symbol,
e.g. x is bound in λ x -> x y
A variable is otherwise free,
e.g. y is free in λ x -> x y
Lambda calculus
Scope of a binding
Everything coming after the lambda definition of the variable,
e.g. e1 is the scope of x in λ x -> e1
Lambda calculus
Scope of an abstraction
All values given with lambda symbols,
e.g. x is in the scope and y isn’t of λ x -> x y
Lambda calculus
Closed term
A lambda calculus term with no free variables is closed
Bind (>>=)
Takes a structured value and a function that may produce a structured result, and applies the latter to the former to produce a structured result:>>= : (f a) -> (a -> f b) -> (f b)
return
Takes a value of data type a
, and returns the value as a Maybe
data type, e.g. m a
java.util.Stream
Intermediate operators
- filter
- peek
- distinct
- sorted
- iterate
java.util.Stream
Terminal operations
- forEach
- toArray
- reduce (inc. max, min, count)
- collect
Isomorphism between two data types T
and U
An isomorphism exists if there exists are a pair of functions taking T -> U
and U -> T
,
and T
and U
have an equal size
Monad properties
Associativity and Distributivity