From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 0E04FBB83 for ; Mon, 3 Jul 2006 15:51:33 +0200 (CEST) Received: from mx1.polytechnique.org (mx1.polytechnique.org [129.104.30.34]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k63DpXql005497 for ; Mon, 3 Jul 2006 15:51:33 +0200 Received: from is003364.intra.cea.fr (is003364.intra.cea.fr [132.166.133.48]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTP id 948EE331F8 for ; Mon, 3 Jul 2006 15:51:32 +0200 (CEST) Date: Mon, 3 Jul 2006 15:51:31 +0200 From: Virgile Prevosto To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Type from local module would escape its scope? Message-ID: <20060703155131.7031cffa@is003364.intra.cea.fr> In-Reply-To: <069A1F65-E50C-4363-9CCA-C6CC9A453D09@vub.ac.be> References: <069A1F65-E50C-4363-9CCA-C6CC9A453D09@vub.ac.be> X-Mailer: Sylpheed-Claws 2.1.1 (GTK+ 2.8.18; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-AV-Checked: ClamAV using ClamSMTP at djali.polytechnique.org (Mon Jul 3 15:51:32 2006 +0200 (CEST)) X-Org-Mail: virgile.prevosto.1996@polytechnique.org X-Miltered: at concorde with ID 44A920E5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; foo:01 sig:01 val:01 foo:01 struct:01 pervasives:01 denotes:01 annotation:01 ocaml:01 val:01 iirc:01 forall:01 sig:01 struct:01 2006:98 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Le lun 03 jui 2006 15:19:35 CEST, Bruno De Fraine a écrit : > module type FOO = > sig > type t > val value : t > end ;; > let foo (ignore: 'a -> unit) = > let module Foo : FOO = > struct > type t = int > let value = 1 > end in > ignore Foo.value > ;; > > With an error on the expression "Foo.value" stating that "The type > constructor Foo.t would escape its scope". Reading about the typical > case for this error message in http://caml.inria.fr/pub/ml-archives/ > caml-list/2002/10/0cf087feab3ef8dc5ccba5a8592472fb.en.html didn't > really help me. Why does it make a difference whether ignore is an > argument? > Because "'a -> unit" does not mean the same thing in both cases. In the case of Pervasives.ignore, it is a type scheme which denotes all the types you can obtain by instantiating 'a. On the contrary, when used as a type annotation to your argument, "'a -> unit" only tells ocaml that there exists an 'a such that the argument ignore has this type: you can see that with the following code: # let foo (ignore: 'a -> unit) = ignore 1;; val foo : (int -> unit) -> unit = where 'a is instantiated by int in the inferred type. IIRC arguments can not have a generalized type of the form "forall 'a, 'a -> unit", but methods and record fields support such types: for instance, you can have: # module type FOO = sig type t val value : t end ;; module type FOO = sig type t val value : t end # let foo (ignore: unit>) = let module Foo: FOO = struct type t = int let value = 1 end in ignore#call Foo.value;; val foo : < call : 'a. 'a -> unit > -> unit = -- E tutto per oggi, a la prossima volta. Virgile