From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.9 required=5.0 tests=DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 29803BBC4 for ; Sat, 18 Apr 2009 00:02:45 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj4DADeZ6ElFk2DWmWdsb2JhbACWOQEBAQEBCAsKBxGnUAeBApAWAQQCAYN6BoVj X-IronPort-AV: E=Sophos;i="4.40,206,1238968800"; d="scan'208";a="26425645" Received: from web63003.mail.re1.yahoo.com ([69.147.96.214]) by mail3-smtp-sop.national.inria.fr with SMTP; 18 Apr 2009 00:02:44 +0200 Received: (qmail 43586 invoked by uid 60001); 17 Apr 2009 22:02:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1240005763; bh=vDQrigHFiD8SgdyvxyzjrBJUtx+cBVWKqQV8dQ+E3xc=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=XBx7rSaG8Hg14yTe6aY6ybM9QZ1s1SESiZTF6HB+T4uIQ78VZSLf0wRfwo9VZgkZ2H0JY/DLx2IbzB7REbTBcfqo4g7UIvb21xCS7Bv/Ur+Gy3MYAI6MCsmO5oQIU0VnI2kAuHaZvfpUx+6Y3dWiCwk2PqMkFSt/R35118XIeUs= DomainKey-Signature:a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=NoOiCBtBjBZA3zrHyvW+2Zps6X7zdlHyRd1PxKSFvxxm3pn+dOJA2b7SEiu1AA23kaDBjnkIRwgKHSBgfUS8bT9CULM5t/KOP1Lv16JBzhEbjREbuqRvzdyZEBIqkWzhP0j0wLdX98nnLPnAHmEOYP3PFj4tkhhbTdwaXb1yyzw=; Message-ID: <323491.43292.qm@web63003.mail.re1.yahoo.com> X-YMail-OSG: F49Z_7oVM1k624Qedz3iL_1TWt_qzgL0WLAgUtd_Reh3ZZZ2GAGeLMLeFQFR5I2r9wjuGq2_rRMPac4hedRFGQFLR1yaNqwYEbKkNnhy75OVzkh91ZlCUYjTn7i4pHLmC2otZR64_e6rfHgIH.Xp6H133NYK6zdy_2M17_P37.JoCJ9w6eEXeveZE359uJ01jrkz704ErpQ.KFB8aVtXWgM53nXhhJ7gAFvw963Bua1gqI.kmUUL.yFb_OQgnkz979S1vew1V5V5MzIgKA-- Received: from [71.125.71.242] by web63003.mail.re1.yahoo.com via HTTP; Fri, 17 Apr 2009 15:02:43 PDT X-Mailer: YahooMailWebService/0.7.289.1 Date: Fri, 17 Apr 2009 15:02:43 -0700 (PDT) From: Arkady Andrukonis Reply-To: grazingcows@yahoo.com Subject: what is the "best" block structure to code a tree structure? To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam: no; 0.00; nodes:01 ocaml:01 ocaml:01 node:01 node:01 nodes:01 tuareg:01 10,:98 20,:98 10,:98 20,:98 .....:98 parentheses:01 parentheses:01 int:01 Hi, I would like to find the easiest block structure to represent nested leaves and nodes in a tree structure that works for OCaml. In Common Lisp there is the help of indentation, but I haven't found one for OCaml. We have one parent node composed of one leaf and a nested node which has another node with two leaves and a leaf (of the second node). To help illustrate the level of depth we can use numbers 10, 20, and 30. (* ------------------- our type definition ------------------- *) # type tree = Node of tree * tree | Leaf of int;; (* ------------ and our tree ------------ *) # Node ((Leaf 10), (Node ((Node ((Leaf 20),(Leaf 30))), Leaf 30)));; -: tree = Node (Leaf 10, Node (Node (Leaf 20, Leaf 30), Leaf 30)) Figuring out the two components to each node and grouping them within parentheses is exceedingly hard for nested nodes without using a block structure. It's great if I can figure this out, but the code is unmaintanable for anyone else. Would you say it is better when written as (I added the periods to prevent email client from removing the whitespace) Node ..((Leaf 10), (Node .....((Node ((Leaf 20), ........(Leaf 30))), Leaf 30)));; or Node ..((Leaf 10), (Node ................((Node ...................((Leaf 20), (Leaf 30))), (Leaf 30)));; or Node ..((Leaf 10), (Node ................((Node ((Leaf 20), (Leaf 30))), ..............(Leaf 30)));; I've checked the manual and it recommends using white space for clarity and intent. In symmetrical trees the code is beautiful, not so in asymmetrical ones. Tuareg only helps to match parentheses. With kindest regards, kadee