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

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to