List Info

Thread: "ocaml_beginners"::[] Module type signature




"ocaml_beginners"::[] Module type signature
user name
2006-11-24 16:36:29

Hello

I have some problem with the understanding module signatures:
Here is module type

module type ORD_TBL = sig
type key
type value
type tbl
type cur
val set_cursor : tbl -> key -> cur option
val move_next : cur -> cur
val move_prev : cur -> cur
val cell : cur -> (key*value) option
end;;

here is some implementation example
module HashArrTbl = struct
type ('key,'value) tbl = {arr:('key*'value) array;htbl:
('key,int)
Hashtbl.t}
type ('key,'value) cur = {ctbl:('key,'value) tbl;cind:int}
let of_list lst = let ht = Hashtbl.create 100 and arr =
Array.of_list lst in Array.iteri (fun i x ->
Hashtbl.replace ht
(fst x) i) arr ; {arr=arr;htbl=ht}
let set_cursor (t:('key,'value) tbl) (key:'key) = try (Some
{ctbl=t;cind=(Hashtbl.find t.htbl key)})
with Not_found -> None
let move_next cur = {cur with cind=cur.cind+1}
let move_prev cur = {cur with cind=cur.cind-1}
let cell (cur:('key,'value) cur) : ('key*'value) option= try
Some cur.ctbl.arr.(cur.cind) with _ -> None
end;;

How can I "adjust" module with ORD_TBL signature? That is some
module that use the current HashArrTbl implementation but "refines"
it to the module type signature?

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )