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 NAA29057; Mon, 2 Apr 2001 13:06:48 +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 NAA29008 for ; Mon, 2 Apr 2001 13:06:47 +0200 (MET DST) Received: from dpt-info.u-strasbg.fr (dpt-info.u-strasbg.fr [130.79.6.1]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f32B6kj22856 for ; Mon, 2 Apr 2001 13:06:46 +0200 (MET DST) Received: from lambda.u-strasbg.fr (lambda.u-strasbg.fr [130.79.90.63]) by dpt-info.u-strasbg.fr (8.9.3/8.9.3) with ESMTP id NAA02454; Mon, 2 Apr 2001 13:06:07 +0200 Received: from luther by lambda.u-strasbg.fr with local (Exim 3.22 #1 (Debian)) id 14k2Ay-0001KJ-00; Mon, 02 Apr 2001 13:07:12 +0200 Date: Mon, 2 Apr 2001 13:07:12 +0200 To: Sven LUTHER Cc: Hao-yang Wang , caml-list@inria.fr Subject: Re: Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml) Message-ID: <20010402130712.A5083@lambda.u-strasbg.fr> References: <200103302033.MAA00807@imap.filemaker.com> <20010401221502.B635@lambda.u-strasbg.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.15i In-Reply-To: <20010401221502.B635@lambda.u-strasbg.fr>; from luther@dpt-info.u-strasbg.fr on Sun, Apr 01, 2001 at 10:15:02PM +0200 From: Sven LUTHER Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, Apr 01, 2001 at 10:15:02PM +0200, Sven LUTHER wrote: > let f1 = function > | 'A x -> xxx > | 'B x,y -> xx > > > and later : > > let f1 = function > | 'C x,y,z -> xxx > | x -> f1 x > I was trold that this would not work, which after a bit of experimenting is true : Objective Caml version 3.01 # let f1 = function | `A x -> 0 | `B (x,y) -> 1;; val f1 : [< `A of 'a | `B of 'b * 'c] -> int = # let f1 = function | `C (x,y,z) -> 3 | x -> f1 x;; This expression has type [? `C of 'a * 'b * 'c] but is here used with type [< `A of 'd | `B of 'e * 'f] which is not cool, but the following works : # exception Ea of int;; exception Ea of int # exception Eb of int * int ;; exception Eb of int * int # exception Ec of int * int * int ;; exception Ec of int * int * int # let f1 f = try f () with | Ea x -> 0 | Eb (x,y) -> 1 ;; val f1 : (unit -> int) -> int = # let f2 f = try f () with | Ec (x,y,z) -> 2 | exn -> let f () = raise exn in f1 f;; val f2 : (unit -> int) -> int = # let fa () = raise (Ea 1) ;; val fa : unit -> 'a = # let fb () = raise (Eb (1,2)) ;; val fb : unit -> 'a = # let fc () = raise (Ec (1,2,3)) ;; val fc : unit -> 'a = # f1 fa;; - : int = 0 # f1 fb;; - : int = 1 # f2 fc ;; - : int = 2 # f1 fc;; Uncaught exception: Ec (1, 2, 3). # f2 fa;; - : int = 0 # f2 fb;; - : int = 1 So there may be some use for the introduction of extensible types (like the exceptions) after all. Friendly, Sven Luther ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr