caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michal Moskal <malekith@pld-linux.org>
To: Benjamin Geer <ben@socialtools.net>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] polymorphic function not recognised as such
Date: Mon, 15 Dec 2003 13:07:41 +0100	[thread overview]
Message-ID: <20031215120741.GA11364@roke.freak> (raw)
In-Reply-To: <3FDCD850.9090005@socialtools.net>

On Sun, Dec 14, 2003 at 09:38:24PM +0000, Benjamin Geer wrote:
> Jean-Baptiste Rouquier wrote:
> >   compare_things : thing -> thing -> ('a -> 'a -> bool) -> bool
> >doesn't mean that comparison_fun has to be polymorphic, but it means 
> >that any function with type ('a -> 'a -> bool), where 'a is any type, is 
> >acceptable. For instance, the type checker would accept a function of 
> >the type (char -> char -> bool).
> 
> OK, but it seems that the type checker has inferred the type of 
> comparison_fun just by looking at its first use in compare_things, and 
> has decided that it must be monomorphic; this is an incorrect inference. 
>  My naive impression is that if the type checker was willing to accept 
> both uses of comparison_fun as valid (or perhaps if it also looked at 
> the places where compare_things is called), it would conclude that 
> comparison_fun does indeed have to be polymorphic.  In that case, I 
> would get a compile error if I tried to pass a non-polymorphic function 
> to compare_things.  Would this be this asking too much?  (I suspect the 
> answer is yes; I'm just curious...)

Polymorphism in ML is flat, that is all type variables are quantified
before the function, not in the arguments. The type ('a -> foo) -> bar
means forall 'a. ('a -> foo) -> bar, and not (forall 'a. 'a -> foo) -> bar.

This is one of the costs of type inference.

In OCaml you can simulate deep polymorphism with polymorphic records
(but you have to write explicit type then).

-- 
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      parent reply	other threads:[~2003-12-15 12:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-14 19:14 Benjamin Geer
2003-12-14 20:06 ` Jean-Baptiste Rouquier
     [not found] ` <3FDCC2A8.2090901@ens-lyon.org>
2003-12-14 21:38   ` Benjamin Geer
2003-12-14 22:06     ` Olivier Andrieu
2003-12-15 12:07     ` Michal Moskal [this message]

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=20031215120741.GA11364@roke.freak \
    --to=malekith@pld-linux.org \
    --cc=ben@socialtools.net \
    --cc=caml-list@inria.fr \
    /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).