Commit e7f93568 authored by Giuseppe Castagna's avatar Giuseppe Castagna

Changed syntax of types for type parameters

parent aa9f6654
......@@ -5,11 +5,11 @@
type Leaf = <leaf key=Caml_int> 'a
type Leaf('a) = <leaf key=Caml_int> 'a
type Branch = <brch pre=Caml_int bit=Caml_int>[ (Leaf|Branch) (Leaf|Branch) ]
type Branch('a) = <brch pre=Caml_int bit=Caml_int>[ (Leaf('a)|Branch('a)) (Leaf('a)|Branch('a)) ]
type Dict = [] | Branch | Leaf
type Dict('a) = [] | Branch('a) | Leaf('a)
let lowest_bit (x: Caml_int): Caml_int = Pervasives.land x ((0 - x):?Caml_int)
......@@ -25,7 +25,7 @@ let match_prefix (k: Caml_int)(p: Caml_int)(m: Caml_int): Bool =
let zero_bit (k: Caml_int)(m: Caml_int): Bool = Pervasives.land k m = 0
let lookup (k: Caml_int)(d: Dict) : ['a?] =
let lookup (k: Caml_int)(d: Dict('a)) : ['a?] =
match d with
| [] -> []
| <brch pre=p bit=m>[ t0 t1 ] ->
......@@ -35,7 +35,7 @@ let lookup (k: Caml_int)(d: Dict) : ['a?] =
| <leaf key=j> x -> if j=k then [ x ] else []
let join (p0: Caml_int)(t0: Dict\[])(p1: Caml_int)(t1: Dict\[]): Branch =
let join (p0: Caml_int)(t0: Dict('a)\[])(p1: Caml_int)(t1: Dict('a)\[]): Branch('a) =
let m = branching_bit p0 p1 in
if zero_bit p0 m then
<brch pre=(mask p0 m) bit=m>[t0 t1]
......@@ -44,8 +44,8 @@ let join (p0: Caml_int)(t0: Dict\[])(p1: Caml_int)(t1: Dict\[]): Branch =
let insert (c: 'a -> 'a -> 'a) (k: Caml_int) (x: 'a) (t: Dict): Leaf|Branch =
let ins (Leaf|Branch -> Leaf|Branch ; [] -> Leaf )
let insert (c: 'a -> 'a -> 'a) (k: Caml_int) (x: 'a) (t: Dict('a)): Leaf('a)|Branch('a) =
let ins (Leaf('a)|Branch('a) -> Leaf('a)|Branch('a) ; [] -> Leaf('a) )
| [] -> <leaf key=k> x
| (<leaf key=j>y)&t ->
if j=k then <leaf key=k>(c x y)
......@@ -57,14 +57,14 @@ let insert (c: 'a -> 'a -> 'a) (k: Caml_int) (x: 'a) (t: Dict): Leaf|Branch =
else join k (<leaf key=k>x) p t
in ins t
let max (x: 'a)(y: 'a): 'a = if (x >> y) then x else y;;
let max (x: 'a)(y: 'b): 'a|'b = if (x >> y) then x else y;;
let swap (f : 'a -> 'a -> 'a) (x: 'a)(y: 'a): 'a = f y x;;
let merge (c: 'a -> 'a -> 'a): (Dict,Dict) -> Dict =
let merge (c: 'a -> 'a -> 'a): (Dict('a),Dict('a)) -> Dict('a) =
fun aux( ([],[]) -> []
; (Dict,Dict)\([],[]) -> Dict\[]
; (Branch,Branch) -> Branch )
; (Dict('a),Dict('a))\([],[]) -> Dict('a)\[]
; (Branch('a),Branch('a)) -> Branch('a) )
| ([],t) | (t,[]) -> t
| (<leaf key=k>x , t) -> insert c k x t
| (t , <leaf key=k>x) -> insert (swap c) k x t
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment