Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] le neophyte et les modules, types parametres
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Rogoff <bpr@b...>
Subject: Re: [Caml-list] le neophyte et les modules, types parametres
On Wed, 25 Apr 2001, Francois Thomasset wrote:
> Désolé de poser des qustions simplistes mais je suis perdu dans les modules.
> Dans l'idée de construire une table de symboles je définis ceci :
> # type symbol = string * int ;;
> # type comparison = Equiv | Smaller | Greater;;
> # module type ORDERED =
>     sig
>       type 'a t
>       val order : 'a t -> 'a t -> comparison
>     end;;
> module type ORDERED =
>   sig type 'a t val order : 'a t -> 'a t -> comparison end
> # module type AVL_FUNCTOR = functor ( Key : ORDERED ) ->
>   sig
>     type 'a key = 'a Key.t
>     type avl_btree = ('a key * int) btree
>     ...
>   end;;
> The type constructor Key.t expects 1 argument(s),
> but is here applied to 0 argument(s)
> 
> D'accord je suppose que c'est le type 'a qui manque (un jour ce sera les 
> morceaux d'environnement attachés aux symboles, donc je n'ai pas envie de 
> préciser tout de suite) ; mais je ne comprends pas comment le dire autrement 
> que ci-dessus ; quelque chose a du m'échapper...
> 
> Question: how to use a parameter type in a module, cf example above

That looks fine, other than the missing type parameter 'a in your
definition of avl_btree. That would give a different error message than
the one you show though, so I don't understand that message either. 

The following should compile:

type comparison = Equiv | Smaller | Greater;;

module type ORDERED =
  sig
    type 'a t
    val order : 'a t -> 'a t -> comparison
  end;;

type 'a btree = Leaf | Node of 'a * 'a btree * 'a btree;;

module type AVL_FUNCTOR = functor ( Key : ORDERED ) ->
  sig
    type 'a key = 'a Key.t
    type 'a avl_btree = ('a key * int) btree
  end;;

-- Brian


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr