Operations on algebraic data types can be defined by using pattern matching[this is, at least in their example,the same as being able to program using the same code math does:Tree.type = { variant? (Empty: null, Leaf: Int, Node: (l.Tree, r.Tree) };depth(x.tree).int`={ return x`variant ?(empty: 0, leaf: 1, others: 1 +max(depth x`left, depth x`right))} .
. this is a somewhat higher level than would be done in ada,
where you'd have to spell out
how you would be determining what variant a subtree was,
eg: empty(x.tree).truth`= '(return x=nil)
] .
No comments:
Post a Comment