From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 9B466BC57 for ; Mon, 7 Jun 2010 07:15:48 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtgAADIdDExCbwQdkWdsb2JhbACDHZskFQEBAQEJCwoHEQQerT2PdAWBJoMDboNO X-IronPort-AV: E=Sophos;i="4.53,376,1272837600"; d="scan'208";a="60762981" Received: from out5.smtp.messagingengine.com ([66.111.4.29]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 07 Jun 2010 07:15:48 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by gateway1.messagingengine.com (Postfix) with ESMTP id 33740F6D8A; Mon, 7 Jun 2010 01:15:47 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Mon, 07 Jun 2010 01:15:47 -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=D9K1XJxNLB8WL7OOF0kwAkkUeFA=; b=aceVN68aProCbzkeIiEEjQrF+eo/7O9fSRh6xnZGutmDlpCVjO1IoLyhvLlI9QrI7CejWM1JByL3NuCBzZ92vLt+zdg3tTGBoaLUL8RbZkuk4Xb7Munu39qQyE9GIx5Uq06w8zuT1W7vCXeLBEFMZWCaZ6+AKE5C1IFn1xmsyQA= X-Sasl-enc: kJ3aP1KaXv4WcG5Va+mk9dtCEJ4pKkoTtoUBBSNQwKw5 1275887746 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 AAB1A4A7C67; Mon, 7 Jun 2010 01:15:46 -0400 (EDT) Message-ID: <4C0C8080.902@ens-lyon.org> Date: Sun, 06 Jun 2010 22:15:44 -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: <4C0C7F08.3010403@ens-lyon.org> In-Reply-To: <4C0C7F08.3010403@ens-lyon.org> 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 wrote:01 readable:01 readable:01 caml-list:01 pair:01 pair:01 jambon:01 jambon:01 Martin Jambon wrote: > 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 ;-) See, I even did not consider the possibility of using: type 'a t = [ `Leaf of string | `Node of 'a t list ] * 'a Note that point (4) remains valid and based on real experience. Martin -- http://mjambon.com/