caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: John Carr <jfc@mit.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Defeating the value restriction
Date: Fri, 28 Oct 2011 09:05:54 +0900	[thread overview]
Message-ID: <A0C13A7A-804A-41C8-BFBC-6BA06864E91A@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <201110262007.p9QK7CMd028545@outgoing.mit.edu>

On 2011/10/27, at 5:07, John Carr wrote:

> Can I rewrite this function to have the type I requested
> instead of failing type checking?
> 
> let f : ('a * 'a -> 'a) -> int * bool = fun x -> x (0,1), x (true,false)
> 
> I assume the type error is caused by the value restriction.
> The parameter (x) becomes monomorphic when applied, so it
> can not be applied to both types (int*int) and (bool*bool).

Just a comment that this completely unrelated to the value restriction.
ML type inference simply doesn't support polymorphism in function
arguments.

As Jeremy Yallop already answered, OCaml supports this by wrapping
the argument in various things. The most recent way to do that
(and intuitively related with the toplevel behaviour) is to use a first-class
module:

module type S = sig val c : 'a * 'a -> 'a end
let f x = let module X = (val x : S) in X.x (0,1) , X.x (true, false)

Jacques Garrigue

      parent reply	other threads:[~2011-10-28  0:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-26 20:07 John Carr
2011-10-26 20:22 ` Jeremy Yallop
2011-10-28  0:05 ` Jacques Garrigue [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=A0C13A7A-804A-41C8-BFBC-6BA06864E91A@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=jfc@mit.edu \
    /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).