From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA27683; Mon, 7 May 2001 17:34:30 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 RAA27536 for ; Mon, 7 May 2001 17:34:29 +0200 (MET DST) Received: from mail5.microsoft.com (mail5.microsoft.com [131.107.3.121]) by concorde.inria.fr (8.11.1/8.10.0) with SMTP id f47FYRf09673 for ; Mon, 7 May 2001 17:34:28 +0200 (MET DST) Received: from 157.54.9.104 by mail5.microsoft.com (InterScan E-Mail VirusWall NT); Mon, 07 May 2001 08:34:26 -0700 (Pacific Daylight Time) Received: from red-msg-04.redmond.corp.microsoft.com ([157.54.12.74]) by inet-imc-02.redmond.corp.microsoft.com with Microsoft SMTPSVC(5.0.2195.2883); Mon, 7 May 2001 08:33:27 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.0.4688.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: [Caml-list] Record pattern matching Date: Mon, 7 May 2001 08:33:23 -0700 Message-ID: <0C682B70CE37BC4EADED9D375809768A48FDDC@red-msg-04.redmond.corp.microsoft.com> Thread-Topic: Record pattern matching Thread-Index: AcDW3k9Pv69PhK3ER0COEnGdvNZ39AAK2mNQ From: "Don Syme" To: X-OriginalArrivalTime: 07 May 2001 15:33:27.0161 (UTC) FILETIME=[0F88CE90:01C0D70B] Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk In OCaml record patterns may be inexact, i.e. you do not have to specify all the fields. =20 # type x =3D {a:int; b:int};; type x =3D { a : int; b : int; } # function {a=3Da} -> a;; - : x -> int =3D # function {b=3Db} -> b;; - : x -> int =3D # I guess this is considered a feature, but I just wanted to report that in my current situation I actually find it unhelpful. I'm in the process of adding fields to a large number of existing records in a large existing code base, and would like the type checker to notify me every time a pattern match is used against one of these record types - essentially every place where I do such a pattern match I will have some extra work to do and I'd rather the type checker guided me to these locations. If I had encoded the type as a datatype constructor, then the rules are of course different: # type x =3D Foo of int * int;; type x =3D Foo of int * int # function (Foo (x)) -> x Characters 10-17: The constructor Foo expects 2 argument(s), but is here applied to 1 argument(s) It seems you're faced with an unfortunate either-or: you lose some strictness in your type checking (i.e. the type checker ends up catching less bugs), or you lose the syntactic convenience of records. =20 I don't really have a suggestion as to what to do about this, though I guess I would prefer if pattern matching against records was strict, or if an alternative syntax could be used for stricter record patterns. As an aside, I would also prefer it if you did not have to use the "{a=3Da; b=3Db}" syntax but could write "{a; b}". Thanks, Don ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr