caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] le neophyte et les modules, types parametres
@ 2001-04-25 15:49 Francois Thomasset
  2001-04-25 16:16 ` Brian Rogoff
  2001-04-25 16:20 ` Alain Frisch
  0 siblings, 2 replies; 3+ messages in thread
From: Francois Thomasset @ 2001-04-25 15:49 UTC (permalink / raw)
  To: caml-list

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

					François Thomasset.
					INRIA (A3)

Tel: +33 (1) 39-63-54-75
Fax: +33 (1) 39-63-53-30 ou +33 (1) 39-63-59-95
Email: Francois.Thomasset@inria.fr
Smail: INRIA, Rocquencourt, BP 105, 78153 Le Chesnay Cedex, France


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] le neophyte et les modules, types parametres
  2001-04-25 15:49 [Caml-list] le neophyte et les modules, types parametres Francois Thomasset
@ 2001-04-25 16:16 ` Brian Rogoff
  2001-04-25 16:20 ` Alain Frisch
  1 sibling, 0 replies; 3+ messages in thread
From: Brian Rogoff @ 2001-04-25 16:16 UTC (permalink / raw)
  To: Francois Thomasset; +Cc: caml-list

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: TEXT/PLAIN; charset=X-UNKNOWN, Size: 1838 bytes --]

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] le neophyte et les modules, types parametres
  2001-04-25 15:49 [Caml-list] le neophyte et les modules, types parametres Francois Thomasset
  2001-04-25 16:16 ` Brian Rogoff
@ 2001-04-25 16:20 ` Alain Frisch
  1 sibling, 0 replies; 3+ messages in thread
From: Alain Frisch @ 2001-04-25 16:20 UTC (permalink / raw)
  To: Francois Thomasset; +Cc: caml-list

On Wed, 25 Apr 2001, Francois Thomasset wrote:

> Question: how to use a parameter type in a module, cf example above

The same problem has already been discussed on this list (or maybe on
comp.lang.{ml,functional}, not sure), and I think there is no good
solution for the moment. 

This issue struck me again just two hours ago. I wanted to build sets
or hash tables over "stamped" values (using the stamp for
comparison/hashing), so I defined a module whose signature is:

module Stamp :
sig
  type 'a t = { stamp : int; data : 'a }

  val build : 'a -> 'a t
  val data  : 'a t -> 'a
  val compare : 'a t -> 'a t -> int
  val hash  : 'a t -> int
  val equal : 'a t -> 'a t -> bool
end

(I don't want Stamp itself to be a functor, because of the lack of
recursivity between modules).

But then  (Set.Make(Stamp)) doesn't work. There would be no problem
to have a generic implementation of Set on parametrized ordered types.
But then you may want to use it with types parametrized with two type
variables, etc ... The solution is presently to copy the
implementation from stdlib/set.ml. The *only* modification is to replace
in the implementation:
 type t = Empty | Node of t * elt * t * int
with
 type 'a t = Empty | Node of 'a t * 'a elt * 'a t * int
or
 type ('a,'b) t = Empty | Node of ('a,'b) t ...
and so on.

The specification must me changed accordingly. It seems that the
transformation is completely automatic and syntactic.

Would there be any problem to accept in functor applications modules whose
types have extra parameters, reflecting adequate modification on the
result ?  (this is only a typing problem; as far as I understand it,
there is absolutely no problem for runtime; adding type parameters
implies no new coercion of runtime representations)


-- 
  Alain Frisch

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-04-25 16:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-25 15:49 [Caml-list] le neophyte et les modules, types parametres Francois Thomasset
2001-04-25 16:16 ` Brian Rogoff
2001-04-25 16:20 ` Alain Frisch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).