From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 0323EBC57 for ; Mon, 7 Jun 2010 07:09:32 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtgAAFIbDExCbwQdkWdsb2JhbACDHZskFQEBAQEJCwoHEQQerTGPdQWBJoMDboNO X-IronPort-AV: E=Sophos;i="4.53,375,1272837600"; d="scan'208";a="51874205" Received: from out5.smtp.messagingengine.com ([66.111.4.29]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 07 Jun 2010 07:09:32 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by gateway1.messagingengine.com (Postfix) with ESMTP id 3843BF85EE; Mon, 7 Jun 2010 01:09:31 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Mon, 07 Jun 2010 01:09:31 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=message-id:date:from:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; s=smtpout; bh=hJbSmTLu5dWvRjbEVdUzezBctpY=; b=ETBx4KfLjL00Czl3D0zuNNtQ0Ixn/Duo3OhZPtORwndSLng0JVK5O/RZIcsF4fiB7+6bqMxYFRIn04/+hTy6E5m4dIOo+WO/rQDI0mEaxeuOjBve20vQP7LPO0HOm91yRkNDp+3zfT31cXU/oK6Y2jfISzotPWeaLQVxjtn7prM= X-Sasl-enc: tmVlPHWDrNP2jY6JqqB9ab+NnUjrnnB5/egRVBIO6lic 1275887370 Received: from [192.168.2.3] (c-76-102-13-247.hsd1.ca.comcast.net [76.102.13.247]) by mail.messagingengine.com (Postfix) with ESMTPSA id A98414E64D7; Mon, 7 Jun 2010 01:09:30 -0400 (EDT) Message-ID: <4C0C7F08.3010403@ens-lyon.org> Date: Sun, 06 Jun 2010 22:09:28 -0700 From: Martin Jambon User-Agent: Thunderbird 2.0.0.22 (X11/20090908) MIME-Version: 1.0 To: =?UTF-8?B?RGFuaWVsIELDvG56bGk=?= Cc: caml-list List Subject: Re: [Caml-list] Annotated trees References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; ens-lyon:01 annotations:01 node:01 node:01 nodes:01 annotations:01 wrote:01 readable:01 readable:01 caml-list:01 pair:01 pair:01 jambon:01 jambon:01 tuple:02 Daniel Bünzli wrote: > Hello, > > Does anybody have any real world experience in choosing between the > following two representations for a tree augmented with annotations ? > > type 'a t = 'a * [ `Leaf of string | `Node of 'a t list ] > type 'a t = [ `Leaf of 'a * string | `Node of 'a * 'a t list ] > > Which one is more convenient to process, pattern match on, makes code > more readable etc. ? I normally use the second form. I see the following advantages over the tuple form: 1. Pattern-matching is more readable because the most important piece of information comes first: `Leaf (_, s) -> ... | `Node (_, l) -> ... instead of: (_, `Leaf s) -> ... | (_, `Node l) -> ... 2. If needed, writing an annotation_of_t function instead of just using fst is simple enough and not invasive. 3. It is possible to not annotate certain kinds of nodes, or to have different types of annotations depending on the kind of node. 4. The tuple version feels like there are 2 different definitions of a tree node, i.e. it is easy to get confused about whether an annotated node (the pair) or an non-annotated node (second member of the pair) is expected in one given place. 5. I got this habit and therefore I won't change my mind and reject all rational arguments against it ;-) Martin -- http://mjambon.com/