ML data abstractions, Operations on Types




CS152

Chris Pollett

Apr. 27, 2009

Outline

As we talk about the above we'll continue to introduce ML.

Pointers and References

Recursive Datatypes

Functions Using References

Functions Using Recursive Datatypes

Quiz

Which of the following pairs of types best illustrates the process of type currying?

  1. int * int -> string and int -> string -> int
  2. int * int -> string and int -> int -> string
  3. bool * int -> string and int * bool -> string

Type Equivalence

Type Conversion

Type Checking

Type Inference

  +
 / \
[]  i
| \
a  i

Three Conditions for Type Unification

  1. Any type variable unifies with any type expression not involving that variable. i.e., so a type variable 'a would unify with int, int*int, real, 'b * 'c, etc. However, 'a does not unify with 'a vector or with 'a * 'b. This is because 'a occurs already in the given expression and typing should be finite fixed things not involving recursion. The Prolog language makes use of unification at its heart, but for efficiency does not perform this occurs check.
  2. Any two type constants (that is, things like int or char) unify only if they are the same type.
  3. Any two type constructions (array, struct, recursive types) unify only if they are applications of the same type constructor and all of their component types also unify.