caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Benoit de Boursetty <debourse@email.enst.fr>
To: caml-list@inria.fr
Subject: Ask for explanation -- possibly repeated
Date: Wed, 8 Dec 1999 06:07:15 +0100 (MET)	[thread overview]
Message-ID: <Pine.GSO.4.02.9912080450550.1189-100000@young.enst.fr> (raw)

  Hi

  My question must already have been asked, but the error I get from the
compiler does not seem to be listed in the documentation
("This kind of expression is not allowed as right-hand side of `let rec'")

  So here's the situation. I have a basic, standard structure for trees.

# type 'a classical_tree = Classical_node of 'a * 'a classical_tree list

And now I'd like to move to another tree structure (cyclic by default)
where each node or leaf points to its parent node, if there is one.

So I want to use the following type:

# type 'a tree = Node of 'a tree option * 'a * 'a tree list

which means: Node (parent node, data, sons).

I can easily create such typed values by hand:

# let rec root = Node (None, 0, [son1; son2])
  and son1 = Node (Some root, 1, [])
  and son2 = Node (Some root, 2, []);;


But I can't manage to write the translation function from the first type
to the second one in a purely applicative fashion. It is intuitive to
write:

# 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

but of course this doesn't work ("This kind of expression is not allowed
as right-hand side of `let rec'", as they say) and I understand why. It's
because the contents of "this_node", not yet defined, could be looked at
in function "aux". In fact this is a correct algorithm only because
argument "father" is not accessed to in function "aux".

So, is there an applicative workaround? I know how to do it with mutable
values / references, but...

Benoit de Boursetty.





             reply	other threads:[~1999-12-08 19:59 UTC|newest]

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

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.9912080450550.1189-100000@young.enst.fr \
    --to=debourse@email.enst.fr \
    --cc=Benoit.de-Boursetty@polytechnique.org \
    --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).