caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Instanciating functor types with extra parameters
@ 2007-08-04 16:03 Arnaud Spiwack
  2007-08-04 16:15 ` [Caml-list] " Denis Bueno
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Arnaud Spiwack @ 2007-08-04 16:03 UTC (permalink / raw)
  To: Caml List

Hi caml list !

The recent, or rather current, thread on priority queues, raised back an 
issue that've I've been really infuriated with a couple of time the 
past, like, 2 years.

When I have a functor type, like for example (not too innocent I'm afraid) :

module type OrderedType =
  sig
    type t
    val compare : t -> t -> int
  end


Something that naive intuition would allow you to do is something like :

module GenOrder : OrderedType =
  struct
    type t = 'a
    let compare = compare
  end


Though this is more or less nonsense. And is not currently possible 
under OCaml type system.

My point is that I know absolutely no way of doing such a thing. Hence I 
can't make a set with total or partial genericity. If I want to add type 
parameters I have to rewrite the *whole* set library. Actually... I've 
got to copy past it, and replace all occurences of    t   with an 'a t 
for instance. Or ('a,'b) t if I have two arguments. I really had to do 
that once, and almost a couple of other time. That's why it infuriates 
me as I said earlier.

The whole issue is that it totaly breaks the purpose of functors to have 
to recast it for a very small type variation.

Thus I'm raising the question : is there a good reason (I mean a good 
reason from the user point of view here, I kinda understand it may make 
things much more complicated). An other question would be : is there a 
way to work around this issue ? Yet another question would be : should 
there be a separated syntax to mean that the type can have arbitrary 
arguments encapsulated ?


PS : I'm aware that there is (several) available implementation of 
unfunctorized Set and Map, the questions are about the more general case 
though. I very often give up the idea of writing something in a 
functorized style, because it's too fragile, which is a bit paradoxal to me.





Arnaud Spiwack


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

end of thread, other threads:[~2007-08-06 13:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-04 16:03 Instanciating functor types with extra parameters Arnaud Spiwack
2007-08-04 16:15 ` [Caml-list] " Denis Bueno
2007-08-04 18:51 ` rossberg
2007-08-04 19:13 ` Oliver Bandel
2007-08-06 13:47 ` Mike Furr

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).