From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id C6FD2BBFA for ; Mon, 20 Jun 2005 18:19:49 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j5KGJna4012247 for ; Mon, 20 Jun 2005 18:19:49 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA14613 for ; Mon, 20 Jun 2005 18:19:49 +0200 (MET DST) Received: from qrnik.knm.org.pl (paf87.warszawa.sdi.tpnet.pl [217.96.225.87]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j5KGJlMF009697 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 20 Jun 2005 18:19:48 +0200 Received: from qrczak by qrnik.knm.org.pl with local (Exim 3.36 #1) id 1DkOzt-0005SA-00 for caml-list@inria.fr; Mon, 20 Jun 2005 18:19:41 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] signature and 'a generic types X-Face: .B/ouEO}=VFkSJWE}s0@!:diHI.Z,`m}AqK#Vjuscq(Vf1B}H[)v\9tBN}>AdP,QSRbhO]=v 3?;I+cN/Z0HKPm_Eg99/pFrU!WfpjgQ!z":>A~qt0^4):0-UuPB(6^>j!mN$)RIb)rRhXeK:+MLPW[ RVb7Kepvby-ww6_zci7Yy_@IrWW References: From: "Marcin 'Qrczak' Kowalczyk" Mail-Followup-To: caml-list@inria.fr Date: Mon, 20 Jun 2005 18:19:41 +0200 In-Reply-To: (Damien Bobillot's message of "Mon, 20 Jun 2005 17:20:40 +0200") Message-ID: <871x6xvw4i.fsf@qrnik.zagroda> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: "Marcin 'Qrczak' Kowalczyk" X-Miltered: at nez-perce with ID 42B6ECA5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 42B6ECA3.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 damien:01 damien:01 sig:01 val:01 func:01 struct:01 func:01 subtype:01 subtype:01 forall:01 forall:01 sig:01 val:01 struct:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: Damien Bobillot writes: > module Module : (sig val func : 'a -> 'b end) = > struct let func a = a end > > Here Module.func's type is 'a -> 'a. According to me 'a -> 'a is a > subtype of 'a -> 'b, it's 'a -> 'b with 'a = 'b. It's not a subtype because 'a -> 'b really means forall 'a 'b. 'a -> 'b and not exists 'a 'b. 'a -> 'b If identity function had type forall 'a 'b. 'a -> 'b, I could use it to transform an integer to a string. > module Module : (sig val func : 'a -> 'a end) = struct > let l = ref [] > let func a = List.assoc a !l Here the type of func is '_a -> '_b which means something like exists 'a 'b. 'a -> 'b For details Google for "value polymorphism" or "imperative polymorphism". (Why this is not explained in OCaml manual?) This is not a subtype of forall 'a. 'a -> 'a. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/