From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 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 A3685BC0A for ; Tue, 27 Feb 2007 05:38:04 +0100 (CET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1R4c2dG007456 for ; Tue, 27 Feb 2007 05:38:03 +0100 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id l1R4bwGi018006; Tue, 27 Feb 2007 13:37:59 +0900 (JST) Date: Tue, 27 Feb 2007 13:37:56 +0900 (JST) Message-Id: <20070227.133756.51862929.garrigue@math.nagoya-u.ac.jp> To: lukstafi@gmail.com Cc: ocaml_beginners@yahoogroups.com, caml-list@inria.fr Subject: Re: [Caml-list] Re: "ocaml_beginners"::[] Syntax for polymorphic methods From: Jacques Garrigue In-Reply-To: <4a708d20702261102x38ac9fd6v5cdefa9c436de9eb@mail.gmail.com> References: <4a708d20702260334i47bbde3fgcdf2ca2c296338c8@mail.gmail.com> <301730110702260959i561902dar1a26dceb5a11fd2c@mail.gmail.com> <4a708d20702261102x38ac9fd6v5cdefa9c436de9eb@mail.gmail.com> X-Mailer: Mew version 4.2 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 45E3B5AA.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 syntax:01 lukasz:01 val:01 bool:01 parmatch:01 bug:01 forall:01 compiler:01 bool:01 pty:98 pty:98 polymorphic:01 polymorphic:01 beginners:01 From: "Lukasz Stafiniak" > Objective Caml version 3.09.3 > > # type pty = {pv : 'a . 'a list};; > type pty = { pv : 'a. 'a list; } > # let px = {pv = []};; > val px : pty = {pv = []} > # match px with > {pv=[]} -> "OK" > | {pv=5::_} -> "int" > | {pv=true::_} -> "bool";; > Fatal error: exception Assert_failure("typing/parmatch.ml", 784, 55) Thanks for finding a small bug. The code above is meaningless: only the empty list has type forall 'a. 'a list. Yet one could write it, and invalidate some internal invariant of the compiler. Now (for 3.10) this triggers an error message: The record field label pv is polymorphic. You cannot instantiate it in a matching. An aside of the fix is that matching a polymorphic field with a variable now generates a polymorphic binding. # fun {pv=v} -> true::v, 1::v;; - : pty -> bool list * int list = Jacques Garrigue