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 F08EEBC69 for ; Tue, 24 Oct 2006 23:55:11 +0200 (CEST) Received: from ptb-relay02.plus.net (ptb-relay02.plus.net [212.159.14.213]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id k9OLtBQt008248 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Tue, 24 Oct 2006 23:55:11 +0200 Received: from [80.229.56.224] (helo=[10.0.0.5]) by ptb-relay02.plus.net with esmtp (Exim) id 1GcUEb-0004Wy-WB for caml-list@yquem.inria.fr; Tue, 24 Oct 2006 22:54:58 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Simple(?) subtyping problem... Date: Tue, 24 Oct 2006 22:53:20 +0100 User-Agent: KMail/1.9.4 References: <9d3ec8300610241345k1600fd9dqe3a3bba5c4bd9def@mail.gmail.com> In-Reply-To: <9d3ec8300610241345k1600fd9dqe3a3bba5c4bd9def@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200610242253.20095.jon@ffconsultancy.com> X-Miltered: at discorde with ID 453E8BBF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; subtyping:01 messes:01 val:01 val:01 ocaml:01 frog:98 wrote:01 extensible:01 caml-list:01 functions:01 variant:02 caml:02 archives:02 objective:02 unit:03 On Tuesday 24 October 2006 21:45, Till Varoquaux wrote: > I'm currently trying to split functions matching against given variant > type and I'm running across this pb: > > let a= function > > | `A -> () > | `B -> () > > doesn't split into > > let c=function > > | `B -> () > > let b =function > > | `A -> () > | x -> c x > > since it messes up the type rules. I really want to avoid having to > write down precise type informations (The point here is to have an > extensible system)... How about: # type c = [`B];; type c = [ `B ] # let c = function | #c -> ();; val c : [< c ] -> unit = # let b k = function | `A -> () | #c as x -> c x | x -> k x;; val b : (([> `A | `B ] as 'a) -> unit) -> 'a -> unit = > I am sure this question has been asked loads of times (but I couldn't > find the right thread in the archives) and I apologize for asking it > yet again. I don't think it comes up very often. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists