From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p9S066c8029313 for ; Fri, 28 Oct 2011 02:06:06 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgwDAGLxqU7RVdivkGdsb2JhbABCDqhFgQcIIgEBAQEJCQ0HFAQhgXIBAQEDARICExMGATgBAwELAQUFDiYSNAEFARwGNYdgmEMKjjOFCIktAgUKiBNhBIgEjAmGWYZaPYFJgW9G X-IronPort-AV: E=Sophos;i="4.69,415,1315173600"; d="scan'208";a="115228700" Received: from mail-qy0-f175.google.com ([209.85.216.175]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Oct 2011 02:06:00 +0200 Received: by qyk35 with SMTP id 35so1611521qyk.6 for ; Thu, 27 Oct 2011 17:05:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=GdqXrNKd0oRjmSFoH1XGRiW3fUUl1ItQ0I54XRfs3U0=; b=mrvYMsA5hPsYsUDI44KnSAfmXLkqHuYKXjdFnSX4G5k31u6AIokl5qjs/Zmkny3Oku 3AIfIhwCfNhOxQGm4XPj4aQYcT+4uOywy/dGUn54xaBJyKtNJhf4Z++gWvTl3bfQiSi4 o8fmrUdIs4oKgoa14uccgetpMoWeLyvhDQJww= Received: by 10.68.36.5 with SMTP id m5mr1129703pbj.53.1319760359209; Thu, 27 Oct 2011 17:05:59 -0700 (PDT) Received: from tet.garrigue.jp (58x158x128x157.ap58.ftth.ucom.ne.jp. [58.158.128.157]) by mx.google.com with ESMTPS id 4sm18670586pbj.18.2011.10.27.17.05.56 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Oct 2011 17:05:57 -0700 (PDT) Sender: Jacques Garrigue Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Jacques Garrigue In-Reply-To: <201110262007.p9QK7CMd028545@outgoing.mit.edu> Date: Fri, 28 Oct 2011 09:05:54 +0900 Cc: caml-list@inria.fr Content-Transfer-Encoding: 7bit Message-Id: References: <201110262007.p9QK7CMd028545@outgoing.mit.edu> To: John Carr X-Mailer: Apple Mail (2.1084) Subject: Re: [Caml-list] Defeating the value restriction 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