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 TAA21961; Sun, 18 Aug 2002 19:50:23 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA22643 for ; Sun, 18 Aug 2002 19:50:22 +0200 (MET DST) Received: from lobus.fungible.com (adsl-64-161-114-6.dsl.snfc21.pacbell.net [64.161.114.6]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7IHnbj18633 for ; Sun, 18 Aug 2002 19:49:45 +0200 (MET DST) Received: by lobus.fungible.com (Postfix, from userid 1000) id 712167F63; Sun, 18 Aug 2002 10:49:32 -0700 (PDT) Date: Sun, 18 Aug 2002 10:42:00 -0700 From-Tims-Fingers: true To: caml-list@inria.fr Subject: [Caml-list] Recursion between class and value? Message-Id: <20020818174932.712167F63@lobus.fungible.com> From: tim@fungible.com (Tim Freeman) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I'd like to be able to have a class and a function be mutually recursive, kind of like this: class foo = object method bar x = if x > 0 then baz (x - 1) else () end let baz z = if z > 0 then (new foo)#bar (z - 1) else () The best I know how to do is transform baz into a method on foo, yielding this: class foo = object (self) method bar x = if x > 0 then self#baz (x - 1) else () method baz z = (* Except for the type recursion, this doesn't have to be a method on foo. *) if z > 0 then (new foo)#bar (z - 1) else () end let baz z = (new foo)#baz z The comment points at the ugly part. Is there a better way? -- Tim Freeman tim@fungible.com GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D 7180 76DF FE00 34B1 5C78 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners