Go backward to Record Types
Go up to Top
Go forward to Universal Quantification
Variant Types and Recursion
- Example:
- type AVar = [a: Int, b: String]
value v1: AVar = [a = 3]
value v2: AVar = [b = "abcd"]
- value f = fun(x: AVar)
case x of
[a = anInt] "int"
[b = aString] "string" ^ aString
otherwise "error"
- Recursive function definitions
- rec value fact =
fun(n: Int) if n=0 then 1 else n*fact(n-1)
- Recursive type definitions
- rec type IntList =
[nil: Unit
cons: {head: Int, tail: IntList} ]
Wolfgang.Schreiner@risc.uni-linz.ac.at
Id: understand.tex,v 1.1 1996/06/12 09:38:21 schreine Exp schreine