overloading.cd 682 Bytes
Newer Older
1
type Person = FPerson | MPerson;;
2
3
type FPerson = <person gender=1>[ Name Children ];;
type MPerson = <person gender=2>[ 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
14
15
16
17
let fun sort (MPerson -> Man ; FPerson -> Woman)
   <person gender=g>[ n <children>[(mc::MPerson | fc::FPerson)*] ] ->
       let tag = match g with 1 -> `woman | 2 -> `man in
       let s = map mc with x -> sort x in
       let d = map fc with x -> sort x in	
           <(tag)>[ n  <sons>s  <daughters>d ] in sort;;