caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Rogoff <bpr@best.com>
To: Markus Mottl <mottl@miss.wu-wien.ac.at>
Cc: Tom _ <tom7ca@yahoo.com>, caml-list@inria.fr
Subject: Re: [Caml-list] classes vs modules
Date: Sun, 27 May 2001 13:54:21 -0700 (PDT)	[thread overview]
Message-ID: <Pine.BSF.4.21.0105271331380.656-100000@shell5.ba.best.com> (raw)
In-Reply-To: <20010527181431.A5444@miss.wu-wien.ac.at>

On Sun, 27 May 2001, Markus Mottl wrote:
> Out of curiousity, would it be unsound to allow functions like the
> following:
> 
>   let f (cmp : 'a -> 'a -> bool) =
>     let module SomeSet =
>       Set.Make (struct type t = 'a let compare = cmp end) in
>     ()

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

I use something very much like that in a few places, for example a
"uniquify" function on lists which eliminates duplicates.

I ended up creating polymorphic modules for a few of the stdlib modules on 
account of that old issue about functor instantiations recursive with a
type definition, so as to perform the ugly parameterization hack to
sidestep this ML limitation, but they are useful elsewhere too.

> The compiler complains with:
> 
>   File "foo.ml", line 2, characters 49-51:
>   Unbound type parameter 'a
> 
> This, however, is not true (in any case): 'a is bound by the explicit
> function annotation.

I thought you could never have type variables on the right hand side if
they were'nt also on the left? Besides, currently ML type annotations are 
without teeth, as you are well aware; as a translator of Okasaki's
algorithms you surely miss polymorphic recursion.

-- Brian


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


  reply	other threads:[~2001-05-27 20:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-27 13:31 Tom _
2001-05-27 16:14 ` Markus Mottl
2001-05-27 20:54   ` Brian Rogoff [this message]
2001-05-27 23:13     ` Markus Mottl
2001-05-27 23:52     ` Tom _
2001-05-28  4:15       ` Brian Rogoff
2001-05-28  8:34       ` Andreas Rossberg
2001-05-28  8:24   ` Andreas Rossberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.BSF.4.21.0105271331380.656-100000@shell5.ba.best.com \
    --to=bpr@best.com \
    --cc=caml-list@inria.fr \
    --cc=mottl@miss.wu-wien.ac.at \
    --cc=tom7ca@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).