From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 8DA9ABB81 for ; Thu, 9 Dec 2004 02:27:52 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iB91Rqtt004966 for ; Thu, 9 Dec 2004 02:27:52 +0100 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 CAA05040 for ; Thu, 9 Dec 2004 02:27:51 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iB91Ro44004954 for ; Thu, 9 Dec 2004 02:27:51 +0100 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id iB91Rm6p028759; Thu, 9 Dec 2004 10:27:49 +0900 (JST) Date: Thu, 09 Dec 2004 10:27:35 +0900 (JST) Message-Id: <20041209.102735.45228995.garrigue@math.nagoya-u.ac.jp> To: keiko@kaba.or.jp Cc: caml-list@inria.fr Subject: Re: [Caml-list] Type constraints From: Jacques Garrigue In-Reply-To: <20041209.095602.74680404.keiko@kaba.or.jp> References: <20041208.123051.74739504.keiko@kaba.or.jp> <8002B033-4906-11D9-8195-000D9345235C@inria.fr> <20041209.095602.74680404.keiko@kaba.or.jp> X-Mailer: Mew version 4.0.64 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 41B7AA18.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41B7AA16.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 kaba:01 struct:01 struct:01 polymorphism:01 polymorphism:01 ocaml:01 syntax:01 polymorphic:01 polymorphic:01 functions:01 jacques:01 jacques:01 constraints:01 data:02 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: From: nakata keiko > > > This does not answer to me why this works, > > > > > > #type t = { t : 'a. 'a -> 'a} > > > > > > #let v = let module M = struct let t x = x end in {t = M.t} in (v.t 5, > > > v.t true) > > I have the impression that if the above code is type checked, > then, something like the following code could be type checked. > What is the differences? > > > > #let v : 'a. 'a -> 'a = let module M = struct let t x = x end in M.t > > > in (v 5, v true) These two examples use different kinds of polymorphism. In the first case, the data structure ensures the polymorphism, meaning that even if the type of the data structure is made non-generalizable, you can still extract a polymorphic value from it later. That's why you can pass such values to functions, and use them polymorphically inside (which you cannot do with normal variables.) A simple example of the difference is (fun v -> (v.t 5, v.t true)) {t = fun x -> x} vs. (fun v -> (v 5, v true)) (fun x -> x) There is currently no way to make a first-class polymorphic value in ocaml without using either record or object. (There is no theoretical limitation, just we could never come up with the right syntax for introduction and elimination.) Jacques Garrigue