Re: Ask for explanation -- possibly repeated

From: Pierre Weis (Pierre.Weis@inria.fr)
Date: Sun Dec 12 1999 - 23:33:47 MET


From: Pierre Weis <Pierre.Weis@inria.fr>
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)
In-Reply-To: <199912111827.TAA06475@tobago.inria.fr> from "Damien Doligez" at Dec 11, 99 07:27:50 pm

> >From: Benoit de Boursetty <debourse@email.enst.fr>
> >
> ># 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 = <fun>

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:29 MET