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 00E55BBFA for ; Mon, 20 Jun 2005 17:59:46 +0200 (CEST) Received: from interferon.mpi-sb.mpg.de (mpii.mpg.de [139.19.1.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j5KFxjpV009827 for ; Mon, 20 Jun 2005 17:59:45 +0200 Received: from amavis by interferon.mpi-sb.mpg.de with scanned-ok (Exim 3.36 #1 (Debian)) id 1DkOgb-0006SZ-00 for ; Mon, 20 Jun 2005 17:59:45 +0200 Received: from maildist ([139.19.90.238] helo=mpi-sb.mpg.de) by interferon.mpi-sb.mpg.de with esmtp (Exim 3.36 #1 (Debian)) id 1DkOgZ-0006SG-00 for ; Mon, 20 Jun 2005 17:59:43 +0200 Received: from mpiat2305 (Debian-exim@mpiat2305 [139.19.20.94]) by mpi-sb.mpg.de (8.12.10+Sun/8.12.10) with ESMTP id j5KFxho5001300 for ; Mon, 20 Jun 2005 17:59:43 +0200 (MEST) Received: from localhost.mpi-sb.mpg.de ([127.0.0.1] helo=mpiat2305 ident=prevosto) by mpiat2305 with esmtp (Exim 4.50) id 1DkOgZ-0000Eb-8N for caml-list@yquem.inria.fr; Mon, 20 Jun 2005 17:59:43 +0200 Date: Mon, 20 Jun 2005 17:59:42 +0200 From: Virgile Prevosto To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] signature and 'a generic types Message-ID: <20050620175942.2287baed@mpiat2305> In-Reply-To: References: X-Mailer: Sylpheed-Claws 1.0.0 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by AMaViS perl-11 X-Miltered: at nez-perce with ID 42B6E7F1.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 damien:01 sig:01 val:01 func:01 struct:01 func:01 val:01 sig:01 struct:01 pairs:01 foo:01 2005,:98 tutto:98 oggi:98 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Hi, Le 06/20/2005, =E0 05:20:40 PM, Damien Bobillot a =E9crit: > Look at the following code : >=20 > module Module : (sig val func : 'a -> 'b end) =3D > struct let func a =3D a end > Values do not match: > val func : 'a -> 'a > is not included in > val func : 'a -> 'b >=20 > Why ? because the implementation of func is less general than what the signature expects: if this was accepted, then you could use Module.func in a context where 'a and 'b would get different instantiations. >=20 > I also try to use the reverse match : >=20 > module Module : (sig val func : 'a -> 'a end) =3D struct > let l =3D ref [] > let func a =3D List.assoc a !l > end This is not the "reverse" match, which would rather be module Module: (sig val func: 'a -> 'a end) =3D=20 struct let l =3D []=20 let func a =3D List.assoc a l end;; which is a perfectly well defined module. In your case, problems come from the ref: the type of l (hence of func) is not really polymorphic: it uses what is called weak type variables (that you recognize because of the '_' prefix in '_a and '_b), that on the contrary to normal type variables can not be generalized. Otherwise, it would be possible to add to l pairs of different types, such as in the following example: module Module =3D=20 struct let l =3D ref [] (* type: ('_a * '_b) list *) let func a =3D List.assoc a !l let _ =3D l:=3D (0, "foo")::!l=20 (* after that '_a is bound to int and '_b to string. *) let _ =3D l:=3D ("bar", 1)::!l (* type error. *) end --=20 E tutto per oggi, a la prossima volta Virgile