overloading.cd 865 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
type Children = <children>[Person*];; 
type Name = <name>[String];;
6
7
8
9
10
11

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
       let tag = match g with "F" -> `woman | "M" -> `man in
15
       let s = map mc with x -> sort x in
16
       let d = map fc with x -> sort x in	
17
           <(tag)>[ n  <sons>s  <daughters>d ] 
18
19
20
21
22
23
24
25
26
27
28
29
in 
let base : Person = 
<person gender="F">[ 
  <name>"Veronique"
  <children>[ 
    <person gender="F">[
      <name>"Ilaria"
      <children>[]
     ]
  ]
]
in sort base;;