[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Pierre Weis <Pierre.Weis@i...> |
| Subject: | Re: Ask for explanation -- possibly repeated |
> >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/