On Fri, Nov 24, 2006 at 04:36:29PM -0000, mnovoseltsev wrote:
> 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?
In theory you'd do this:
module MyModule : ORD_TBL = struct
include HashArrTbl
type key = string
type value = int
end
but this isn't going to work because your type ('key, 'value) tbl
isn't compatible with the plain type tbl in the signature.
Perhaps you meant to use a functor? It's hard to tell because I'm not
really sure what problem you're trying to solve. A generic table
type?
Rich.
--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Internet Marketing and AdWords courses - http://merjis.com/courses - NEW!
Merjis blog - http://blog.merjis.com - NEW!
.