Go backward to Basic and Structured Types
Go up to Top
Go forward to Variant Types and Recursion
Record Types
- Example:
- type ARec = {a: Int, b: Bool}
value r: ARec = {a = 3, b = true}
r.b
- Functions as components:
- type FunRec = {f1: Int Int, f2: Real
Real}
value funRec: FunRec = {f1 = succ, f2 = sin}
- Concatenation of record types:
- type NewRec = FunRec & {f3: Bool Bool}
- Private data structures:
- value counter =
let count = ref(0) in
{ inc = fun(n:Int) count := count+n
total = fun() count
}
- counter.inc(3), counter.total()
Wolfgang.Schreiner@risc.uni-linz.ac.at
Id: understand.tex,v 1.1 1996/06/12 09:38:21 schreine Exp schreine