From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 4E678BBAF for ; Thu, 9 Dec 2010 05:57:31 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ag8BAOLw/0zRVdaukGdsb2JhbACVFYYvAYgcCBYBAQEJCQwHEQQlphSJbIIYhQQuiFYBAQMFhUQEgV6DBIYP X-IronPort-AV: E=Sophos;i="4.59,319,1288566000"; d="scan'208";a="82298898" Received: from mail-iw0-f174.google.com ([209.85.214.174]) by mail4-smtp-sop.national.inria.fr with ESMTP; 09 Dec 2010 05:57:04 +0100 Received: by iwn9 with SMTP id 9so2896156iwn.5 for ; Wed, 08 Dec 2010 20:57:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type; bh=wHIvxWazOhIg8c7H/Ydld9BeDbxdtDqERzkRc6k7n7k=; b=bvvISi+FirVkKJIbI5LsQ4eZjNrpsksGp0HF8dUUQRXA35JPneDihyQHJYD4byLhca S9q5/gO2y8xzzNS9KFAheumCCKoztVkCglzhV2fnGB/odDw4Ae8vqNO+qcjIcAidXfFi ydRgQGF62/9/K110s9HgjRK6ci5ut8c3Lgb2M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=tXoYEUxrSabLFJ4GeL9xpSx04UWVWLfl3ogCKV+QEGXw0ACbA5XwbSx1OYX8zPt9rg qi1k+t8oFOh577uuDDMtMa4pGIzTmOHoQBS0Ogifg7CuhQpiycXwi45+FLu0t84vx1Zw UfGkqT66NW3dX1q8AbrRmw+clTirCFwnoKRFQ= Received: by 10.231.38.2 with SMTP id z2mr87777ibd.142.1291870623697; Wed, 08 Dec 2010 20:57:03 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.11.132 with HTTP; Wed, 8 Dec 2010 20:56:43 -0800 (PST) In-Reply-To: <4D005F51.8070701@wp.pl> References: <4D005F51.8070701@wp.pl> From: Ashish Agarwal Date: Wed, 8 Dec 2010 23:56:43 -0500 Message-ID: Subject: Re: [Caml-list] Define parser and printer consistently To: Dawid Toton Cc: caml-list Content-Type: multipart/alternative; boundary=00221504879b9f0b7f0496f31183 X-Spam: no; 0.00; parser:01 combinators:01 parser:01 ocaml:01 minimized:01 beginner's:01 ocaml:01 bug:01 combinators:01 minimized:01 beginner's:01 bug:01 1975:98 beginners:01 beginners:01 --00221504879b9f0b7f0496f31183 Content-Type: text/plain; charset=ISO-8859-1 Maybe you will find Pickler Combinators useful: http://research.microsoft.com/en-us/um/people/akenn/fun/picklercombinators.pdf On Wed, Dec 8, 2010 at 11:47 PM, Dawid Toton wrote: > I'm going to define a parser and a printer for a simple grammar. > Is there a way to define both of them in a single construct using some > existing OCaml tool? > > For example, I have a keyword "function". The usual parser would contain a > mapping like: > "function" -> `Function > and the straightforward printer would do: > `Function -> "function" > > What is the best way to combine these definitions, so that duplication > would be minimized? > To be precise, avoiding duplication is not exactly what I need. I'm looking > for something that would prevent making inconsistent changes to the parser > and the printer. > > Dawid > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --00221504879b9f0b7f0496f31183 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Maybe you will find Pickler Combinators useful:


On Wed, Dec 8, 2010= at 11:47 PM, Dawid Toton <d0@wp.pl> wrote:
I'm going to define a parser and a printer for a simple grammar.
Is there a way to define both of them in a single construct using some exis= ting OCaml tool?

For example, I have a keyword "function". The usual parser would = contain a mapping like:
"function" -> `Function
and the straightforward printer would do:
`Function -> "function"

What is the best way to combine these definitions, so that duplication woul= d be minimized?
To be precise, avoiding duplication is not exactly what I need. I'm loo= king for something that would prevent making inconsistent changes to the pa= rser and the printer.

Dawid

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--00221504879b9f0b7f0496f31183--