overloading.cd 719 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
type Person = FPerson | MPerson;;
type FPerson = <person gender="F">[ Name Children ];;
type MPerson = <person gender="M">[ Name Children ];;
type Children = <children>[Person*];;
type Name = <name>[String];;

type Man = <man>[ Name Sons Daughters ];;
type Woman = <woman>[ Name Sons Daughters ];;
type Sons = <sons>[ Man* ];;
type Daughters = <daughters>[ Woman* ];;

let fun sort (MPerson \(\synarrow\) Man ; FPerson \(\synarrow\) Woman)
   <person gender=g>[ n <children>[(mc::MPerson | fc::FPerson)*] ] \mred
       let tag = match g with "M" \mred `man | "F" \mred `woman in
       let s = map mc with x \mred sort x in
       let d = map fc with x \mred sort x in	
           <(tag)>[ n  <sons>s  <daughters>d ];;