overloading.cd 712 Bytes
Newer Older
1
type Person = FPerson | MPerson;;
2
3
type FPerson = <person gender=["F"]>[ Name Children ];;
type MPerson = <person gender=["M"]>[ Name Children ];;
4
5
6
7
8
9
10
11
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* ];;

12
13
let fun sort (MPerson -> Man ; FPerson -> Woman)
   <person gender=g>[ n <children>[(mc::MPerson | fc::FPerson)*] ] ->
14
15
       let tag = match g with ["F"] -> `woman | ["M"] -> `man in
       let s = map mc with (x & MPerson) -> sort x in
16
       let d = map fc with x -> sort x in	
17
18
           <(tag)>[ n  <sons>s  <daughters>d ] 
in sort;;