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 JAA29843; Tue, 19 Jun 2001 09:12:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA30708 for caml-list@pauillac.inria.fr; Tue, 19 Jun 2001 09:12:53 +0200 (MET DST) 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 OAA18441 for ; Mon, 18 Jun 2001 14:13:13 +0200 (MET DST) Received: from morgon.inria.fr (morgon.inria.fr [128.93.8.33]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f5ICCen05599; Mon, 18 Jun 2001 14:12:40 +0200 (MET DST) Received: (from remy@localhost) by morgon.inria.fr (8.9.3/8.9.3) id OAA31058; Mon, 18 Jun 2001 14:15:22 +0200 To: Tyng-Ruey Chuang Cc: caml-list@inria.fr, Jean-Christophe.Filliatre@lri.fr (Jean-Christophe Filliatre) Subject: Re: [Caml-list] Weird types References: <200106180804.QAA18021@iota.iis.sinica.edu.tw> From: Didier Remy Date: 18 Jun 2001 14:15:21 +0200 In-Reply-To: Tyng-Ruey Chuang's message of "Mon, 18 Jun 2001 16:04:32 +0800 (CST)" Message-ID: X-Mailer: Gnus v5.7/Emacs 20.4 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Tyng-Ruey Chuang writes: > Jean-Christophe FILLIATRE wrote: > > Actually, there is a type-able way of writing this function, which > > consists in duplicating it into two functions, like this: > > > > ====================================================================== > > type ('a,'b,'c) t = > > | A of 'a * 'b * 'c > > | B of ('b, 'a, 'c) t > > > > let rec gamma = function > > | A _ -> 0 > > | B x -> 1 + gamma' x > > > > and gamma' = function > > | A _ -> 0 > > | B x -> 1 + gamma x > > ====================================================================== > > > > which gives the expected types: > > > > ====================================================================== > > val gamma : ('a, 'b, 'c) t -> int = > > val gamma' : ('a, 'b, 'c) t -> int = > > ====================================================================== > > Interesting! But then size of the duplicated code grows exponentially. Actually, you can share a little more: let gamma_body gamma = function | A _ -> 0 | B x -> 1 + gamma x let rec gamma x = gamma_body gamma' x and gamma' x = gamma_body gamma x;; ;; and a for three parameters: type ('a, 'b, 'c) sigma = | I of 'a * 'b * 'c | T of ('b, 'a, 'c) sigma | P of ('b, 'c, 'a) sigma let body gT gP = function | I _ -> 0 | T x -> 1 + gT x | P x -> 1 + gP x let rec abc s = body bac bca s and acb s = body cab cba s and bac s = body abc acb s and bca s = body cba cab s and cab s = body acb abc s and cba s = body bca bac s ;; Didier ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr