English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] classes vs modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-05-27 (23:52)
From: Tom _ <tom7ca@y...>
Subject: Re: [Caml-list] classes vs modules
> You can do this now if you make a PolySet module by
> copying the
> "monomorphic" implementation from the stdlib,
> changing elt and t to 
> 'a elt and 'a t and, using that instead of Set,
> something like:
> let f (cmp : 'a -> 'a -> bool) =
>   let module SomeSet =
>     PolySet.Make 
>       (struct type 'a t = 'a let compare =
> Pervasives.compare end) in
>   ()

Thanks; that's very useful to know, and it seems
to be working.  I think it might be useful to feature
the ability to have polymorphic types in modules
a little more prominently in the documentation.
Maybe some of the standard modules could take
advantage of this more (it would require some
changes to their interfaces, I suppose).

The type signatures I get out of my module after
converting it are a little odd looking:

    type 'a t = 'a
    type 'a tree = Empty | Node of ...
    val insert :
	('a t t t -> 'a t t -> bool) -> 
	'a t t t -> 'a t tree -> 'a tree

Is there any useful information in the different
number of t's?  They should all be equivalent, right?

BTW, I opted for just passing the "lt" function
as explicit arguments to all the functions in the
module that need them.  That seems like the most
general approach, although it means some extra
arguments and it doesn't guarantee consistency,
as people might pass incompatible versions of "lt"
to different calls; a more convenient interface can
then be wrapped around that, maybe in a different


Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr