Version franēaise
Home     About     Download     Resources     Contact us    
Browse thread
Problem with module inclusion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Christophe_Filliātre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] Problem with module inclusion
Fabrice Marchant a écrit :
>  Here is a counter functor : *)
> [...]
> (*  before Counters, that would be modified this way : 
>  *)
> module Counters ( X : Map.OrderedType ) :
>   sig
>     module XMap :
>       sig
>         type 'a t = 'a Map.Make(X).t
>         val empty : 'a t
>         val add : X.t -> 'a -> 'a t -> 'a t
>         val find : X.t -> 'a t -> 'a
>         val fold : (X.t -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
>         val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
>       end
>     type t = int XMap.t
>     val equal : t -> t -> bool
>     val zeroes : t
>     val incr : t -> X.t -> t
>   end
> =
>   struct
>     module XMap = MapPlus ( Map.Make( X ) )
> 
>       type t = int XMap.t
> 
>       let equal = XMap.equal ( = )
> 
>       let zeroes = XMap.empty
> 
>       let incr map e =
>         (XMap.add e
>           (try succ (XMap.find e map)
>            with Not_found -> 1)) map 
> end
> 
> (* unfortunately this doesn't work : how to access 'to_list' function through the Counters module ? With StringCounters.XMap.to_list ?
> I'm confused. Should the Counters signature be modified ?

You need

- either to export to_list in signature of XMap above as

	val to_list : 'a t -> (X.t * 'a) list

  and then you'll be able to write StringCounters.XMap.to_list in your
 example

- or to re-export it in module Counters, as

	let to_list = XMap.to_list

  and to declare it in signature of module Counters, as

	val to_list : t -> (X.t * int) list

  and then to use it as StringCounters.to_list in your example.

Hope this helps,
-- 
Jean-Christophe