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 XAA17185 for caml-redistribution; Sun, 12 Dec 1999 23:34:04 +0100 (MET) 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 XAA31981 for ; Sun, 12 Dec 1999 23:33:50 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id XAA05150; Sun, 12 Dec 1999 23:33:49 +0100 (MET) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA12778; Sun, 12 Dec 1999 23:33:47 +0100 (MET) From: Pierre Weis Message-Id: <199912122233.XAA12778@pauillac.inria.fr> Subject: Re: Ask for explanation -- possibly repeated To: Damien.Doligez@inria.fr (Damien Doligez) Date: Sun, 12 Dec 1999 23:33:47 +0100 (MET) Cc: caml-list@inria.fr In-Reply-To: <199912111827.TAA06475@tobago.inria.fr> from "Damien Doligez" at Dec 11, 99 07:27:50 pm X-Mailer: ELM [version 2.4 PL24 ME8] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis > >From: Benoit de Boursetty > > > ># 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 > > >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 = Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/