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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 2CFE1BBAF for ; Mon, 17 May 2010 18:02:16 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AikCAB8F8UvUTWUIe2dsb2JhbACDGIJil38VAQEWIgQeq0+QU4ElgwFqBA X-IronPort-AV: E=Sophos;i="4.53,248,1272837600"; d="scan'208";a="62960198" Received: from mx4.wp.pl ([212.77.101.8]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 May 2010 18:02:16 +0200 Received: (wp-smtpd smtp.wp.pl 1882 invoked from network); 17 May 2010 18:02:06 +0200 Received: from pfpleia.if.uj.edu.pl (HELO [149.156.90.26]) (d0@[149.156.90.26]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with AES256-SHA encrypted SMTP for ; 17 May 2010 18:02:06 +0200 Message-ID: <4BF16823.6010801@wp.pl> Date: Mon, 17 May 2010 18:00:35 +0200 From: Dawid Toton User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-Version: 1.0 To: caml-list Subject: Re: Phantom types References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [gfMk] X-Spam: no; 0.00; ocaml:01 val:01 val:01 incompatible:01 delayed:01 delayed:01 int:01 int:01 right-hand:01 define:02 expression:02 expression:02 construct:02 binding:02 binding:02 > type 'a t = {l: float} > > Any thoughts ? I think the crucial question is when new record types are born. Here is my opinion: The "=" sign in the above type mapping definition is what I would call "delayed binding". "Early binding" would be equivalent to type tmp = {lab : float} type 'a s = tmp (evaluate the right-hand side first, then define the mapping). The "early binding" creates only one record type, so lab becomes ordinary record label. In the given example of the "delayed binding" the t becomes a machine producing new record types. Hence, the identifier l is not an ordinary record label. It is shared by whole family of record types. We can see it this way: # type 'a t = { la : float } ;; type 'a t = { la : float; } # {la = 0.};; - : 'a t = {la = 0.} So OCaml interpreter doesn't know the exact type of the last expression, but it is clever enough to give it a generalized type. We can use la to construct records of incompatible types: # type 'a t = { la : float } ;; type 'a t = { la : float; } # let yy = ({la = 0.} : int t) ;; val yy : int t = {la = 0.} # let xx = ({la = 0.} : string t);; val xx : string t = {la = 0.} # xx = yy;; Error: This expression has type int t but an expression was expected of type string t I suppose my jargon may be not mainstream, apologies. Dawid