From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id CA389BC88 for ; Sat, 5 Feb 2005 18:04:55 +0100 (CET) Received: from kraid.nerim.net (smtp-106-saturday.nerim.net [62.4.16.106]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j15H4tQT009856 for ; Sat, 5 Feb 2005 18:04:55 +0100 Received: from hector.lesours (ours.starynkevitch.net [62.212.121.80]) by kraid.nerim.net (Postfix) with ESMTP id 64708418AE; Sat, 5 Feb 2005 18:04:54 +0100 (CET) Received: from basile by hector.lesours with local (Exim 4.44) id 1CxTMd-000103-2i; Sat, 05 Feb 2005 18:04:55 +0100 Date: Sat, 5 Feb 2005 18:04:55 +0100 To: Richard Jones Cc: caml-list@yquem.inria.fr Subject: Re: Why can't types and exceptions be nested (was: Re: [Caml-list] Estimating the size of the ocaml community) Message-ID: <20050205170455.GA3705@ours.starynkevitch.net> References: <000f01c50971$baad4840$0100a8c0@mshome.net> <1107403128.32586.223.camel@pelican.wigram> <20050203173556.4acec1c5.ocaml-erikd@mega-nerd.com> <009a01c50a1e$f6c92080$0100a8c0@mshome.net> <20050204103006.GA498@first.in-berlin.de> <20050205131418.GC484@first.in-berlin.de> <20050205163732.GA13169@furbychan.cocan.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20050205163732.GA13169@furbychan.cocan.org> User-Agent: Mutt/1.5.6+20040907i From: Basile STARYNKEVITCH X-Miltered: at nez-perce with ID 4204FCB7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 basile:01 basile:01 ecrivait:01 wrote:01 oliver:01 bandel:01 wrote:01 ocaml:01 syntax:01 struct:01 rec:01 nerim:01 faiencerie:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: Le Sat, Feb 05, 2005 at 04:37:32PM +0000, Richard Jones écrivait/wrote: > On Sat, Feb 05, 2005 at 02:14:18PM +0100, Oliver Bandel wrote: > > ...well.... > > > > type sometimes_t = Integer of int | One_symbol | Another_symbol > > Another annoyance of OCaml is that 'type' definitions (and exception > defns for that matter) can't be nested. I'm a big big fan of nested > functions, and sometimes I want to return a type which is only used > briefly between two nested functions. You can use the let module syntax for that, eg (the example is silly, but it works) # let pubf x = let module Internal = struct type brief_t = { a: string; b: int } let fun1 x = {a= string_of_int x; b= x+2 } let rec fun2 i = if i<=0 then [] else fun1 i :: (fun2 (i-1)) let f x = List.map (fun {a=s; b=n} -> s,n) (fun2 x) end in Internal.f x;; # pubf 4;; - : (string * int) list = [("4", 6); ("3", 5); ("2", 4); ("1", 3)] Regards. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basilestarynkevitchnet aliases: basiletunesorg = bstarynknerimnet 8, rue de la Faïencerie, 92340 Bourg La Reine, France