caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Benoit de Boursetty <debourse@email.enst.fr>
To: Pierre Weis <Pierre.Weis@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: Ask for explanation -- possibly repeated
Date: Mon, 13 Dec 1999 01:25:14 +0100 (MET)	[thread overview]
Message-ID: <Pine.GSO.4.02.9912130055340.26575-100000@young.enst.fr> (raw)
In-Reply-To: <199912122233.XAA12778@pauillac.inria.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
> > [ 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.




  reply	other threads:[~1999-12-13 16:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-11 18:27 Damien Doligez
1999-12-12 22:33 ` Pierre Weis
1999-12-13  0:25   ` Benoit de Boursetty [this message]
1999-12-13 16:21     ` Pierre Weis
  -- strict thread matches above, loose matches on Subject: below --
1999-12-08  5:07 Benoit de Boursetty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.02.9912130055340.26575-100000@young.enst.fr \
    --to=debourse@email.enst.fr \
    --cc=Benoit.de-Boursetty@polytechnique.org \
    --cc=Pierre.Weis@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).