From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA19987 for caml-redistribution; Mon, 13 Dec 1999 17:27:37 +0100 (MET) 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 BAA16067 for ; Mon, 13 Dec 1999 01:25:19 +0100 (MET) Received: from enst.enst.fr (enst.enst.fr [137.194.2.16]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id BAA29665; Mon, 13 Dec 1999 01:25:17 +0100 (MET) Received: from email.enst.fr (muse.enst.fr [137.194.2.33]) by enst.enst.fr (8.9.1a/8.9.1) with ESMTP id BAA20510; Mon, 13 Dec 1999 01:25:16 +0100 (MET) Received: from young.enst.fr (debourse@young.enst.fr [137.194.34.13]) by email.enst.fr (8.9.3/8.9.3) with ESMTP id BAA12785; Mon, 13 Dec 1999 01:25:16 +0100 (MET) Received: from localhost (debourse@localhost) by young.enst.fr (8.8.8+Sun/8.8.8) with SMTP id BAA26682; Mon, 13 Dec 1999 01:25:15 +0100 (MET) Date: Mon, 13 Dec 1999 01:25:14 +0100 (MET) From: Benoit de Boursetty Reply-To: Benoit.de-Boursetty@polytechnique.org To: Pierre Weis cc: caml-list@inria.fr Subject: Re: Ask for explanation -- possibly repeated In-Reply-To: <199912122233.XAA12778@pauillac.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis > ># let translate_tree = > > let rec aux father (Classical_node (data, sons)) = > > let rec this_node = Node (father, data, > > List.map > > (aux (Some this_node)) > > sons) > > in this_node > > in aux None > > [ doesn't compile ] > >So, is there an applicative workaround? I know how to do it with mutable > >values / references, but... > > As usual: hide the side effect into the lazy side of the language that > is usually considered as pure and applicative, add a bit of > eta-expansion if your language does not know lazy evaluation properly, > and you get a simple workaround: > > let translate_tree t = > let rec aux father (Classical_node (data, sons)) = > let rec this_node = lazy (Node (father, data, > List.map > (aux (Some (Lazy.force this_node))) > sons)) > in Lazy.force this_node > in aux None t;; > val translate_tree : 'a classical_tree -> 'a tree = Erm... "eta-expansion" is not that usual to me but... well, with all my respect, your solution doesn't seem to work. (unless it works with version 2.04, I'm still using O'CaML 2.02) # let essai = Classical_node ("Father", [Classical_node ("Son", [])]);; val essai : string classical_tree = Classical_node ("Father", [Classical_node ("Son", [])]) # translate_tree essai;; Stack overflow during evaluation (looping recursion?). Ah ha. So are mutable values a must even outside the Lazy module? Or does your eta-expansion (I don't even know what it means) need a lift... :-) BdB.