From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA03802 for caml-redistribution; Wed, 8 Dec 1999 20:59:18 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA01212 for ; Wed, 8 Dec 1999 06:07:18 +0100 (MET) Received: from enst.enst.fr (enst.enst.fr [137.194.2.16]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id GAA08339 for ; Wed, 8 Dec 1999 06:07:16 +0100 (MET) Received: from email.enst.fr (muse.enst.fr [137.194.2.33]) by enst.enst.fr (8.9.1a/8.9.1) with ESMTP id GAA11081 for ; Wed, 8 Dec 1999 06:07:16 +0100 (MET) Received: from young.enst.fr (young.enst.fr [137.194.34.13]) by email.enst.fr (8.9.3/8.9.3) with ESMTP id GAA05549 for ; Wed, 8 Dec 1999 06:07:16 +0100 (MET) Received: from localhost (debourse@localhost) by young.enst.fr (8.8.8+Sun/8.8.8) with SMTP id GAA01305 for ; Wed, 8 Dec 1999 06:07:15 +0100 (MET) Date: Wed, 8 Dec 1999 06:07:15 +0100 (MET) From: Benoit de Boursetty Reply-To: Benoit.de-Boursetty@polytechnique.org To: caml-list@inria.fr Subject: Ask for explanation -- possibly repeated Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis 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.