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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 24FA9BC6A for ; Tue, 7 Nov 2006 01:12:55 +0100 (CET) Received: from mail.corp.idt.net (mail.corp.idt.net [169.132.25.53]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kA70CsFt011005 for ; Tue, 7 Nov 2006 01:12:54 +0100 Received: from [169.132.9.113] (account saleyn HELO [169.132.9.113]) by mail.corp.idt.net (CommuniGate Pro SMTP 4.2.10) with ESMTP id 184610983; Mon, 06 Nov 2006 19:12:53 -0500 Message-ID: <454FCF85.40508@hq.idt.net> Date: Mon, 06 Nov 2006 19:12:53 -0500 From: Serge Aleynikov User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: Jon Harrop Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] parameterized pattern References: <454FA5F8.5030106@hq.idt.net> <200611062358.54696.jon@ffconsultancy.com> In-Reply-To: <200611062358.54696.jon@ffconsultancy.com> Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 454FCF86.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; annotations:01 ocaml's:01 unify:01 inference:01 val:01 annotations:01 polymorphic:01 wrote:01 wrote:01 caml-list:01 variant:02 tuple:02 construct:02 string:02 string:02 Jon Harrop wrote: > On Monday 06 November 2006 21:15, Serge Aleynikov wrote: > >> Could anyone point at a suitable resource? >> > > I wasn't even aware that you could add type annotations inside a pattern. I had a similar reaction when I saw that construct in the formal language spec. > Your > example will not work simply because OCaml's type system will not allow float > to unify with string. You need some context where type inference will allow > different possibilities, like a tuple containing both a float and a string: > > # let f = function > | (y : float), _ -> print_float y > | _, (s : string) -> print_string s;; > > or a polymorphic variant containing either a float or a string: > > # let f = function > | `F (y : float) -> print_float y > | `S (s : string) -> print_string s;; > val f : [< `F of float | `S of string ] -> unit = > Thanks. Several people also replied clarifying that the type annotations were merely used for aiding the type inferencer. Serge -- Serge Aleynikov Routing R&D, IDT Telecom Tel: +1 (973) 438-3436 Fax: +1 (973) 438-1464