Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Ask for explanation -- possibly repeated
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Benoit de Boursetty <debourse@e...>
Subject: Re: Ask for explanation -- possibly repeated
> ># 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 = <fun>

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.