From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p566h3vx014000 for ; Mon, 6 Jun 2011 08:43:03 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgwCAN117E3RVdy2mGdsb2JhbAA9AQMSpi4IFAEBAQEBCAkNBxQliHGlMowggj6DZTmIYgEBAwaGGwSGcooHiz88g04 X-IronPort-AV: E=Sophos;i="4.65,325,1304287200"; d="scan'208";a="110298808" Received: from mail-vx0-f182.google.com ([209.85.220.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 06 Jun 2011 08:42:58 +0200 Received: by vxc34 with SMTP id 34so4874856vxc.27 for ; Sun, 05 Jun 2011 23:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=BYRiwUElOnovVA3l7hmC1/60jZOqhJtmtA9LU0vqHvo=; b=QQ45jh5J/Sl8a5IBs1fTuSkSJ8sUNHnsg8VzxxPNyEPe6nJ0ha+4Y/fE26Q99VUIG4 yKgRbHGna9Sc/PRPdTe2a7Uz1ktgamYIPhTmPVBTbtP78tfcAsmiSDCOUpK3zWiJdudo NkQZgLhKgOAJq/gwPTjjcd7IZByfeFEvCo3nA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=OkoWGYYiYBzWfcnfYMAavY83isv9PrvlgC5g5y8/2lHpqPpAAaoTXLIP8qbfMDyAxS Oj2JeOAFX73z0CJcUK1xoFYe86BLwxGFjWvQlXiSKuhGEfNyq5T6Y1CiULPsw4BpUBl8 +NcLDONhgjSc6+Z3KUeDOtu1GtRozQE53CQH4= MIME-Version: 1.0 Received: by 10.52.115.33 with SMTP id jl1mr6289076vdb.10.1307342576983; Sun, 05 Jun 2011 23:42:56 -0700 (PDT) Received: by 10.52.101.163 with HTTP; Sun, 5 Jun 2011 23:42:56 -0700 (PDT) In-Reply-To: References: Date: Mon, 6 Jun 2011 15:42:56 +0900 Message-ID: From: Jun Furuse To: Gabriel Scherer Cc: caml-list Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] [ANN] Planck: a small monadic parser combinator library for OCaml Sorry for late reply. > Have you considered writing a defunctionalized version of the parsing > library ? There are two different kinds of closure construction in your > code: > - the "bind" interface requires to be passed a function, which is generally > a closure built on the fly > - the parsing monad itself is a function type (it is a state+error monad, so > written in state-passing style) > > There is not much you can do for the first closure source, if you want to > keep a monadic interface, but the second cause is inessential. You may > defunctionalize the state monad by reifying it into an algebraic datatype. > The monad computation would return a big data structure (instead of a big > function), and you would then write an interpretation function passing the > state around, without any closure construction. Yeah, I had just started some test implementation of this kind, but removed it from the repo before the release. I had fixed the 1st of April as the dead line of the personal weekend project, and it was already in mid May, so I released it. Now I am working on something different (the port of ocamlspot to 3.13 binannot branch), and have no personal time work on Planck, but I am always welcome to hear responses. Thanks! > Moreover, the heavy use of "bind" (which needs a function/closure as > parameter) in your parsing code could be avoided. You may use more parsing > combinators (like <|>) and less binding operators. For example your current > style is to write (v1 <-- p1; v2 <-- p2; return (p1, p2)), you may as well > write something like ((v1,v2) <-- p1 <*> p2; return (v1,v2)), with one less > bind call (the idea is to "currify" successive bindings with product-binding > combinators). I think you should promote the use of combinators over raw > "binds". The preprocessor hack described in my blog post is almost the same effort, and it improved the performance a lot. The idea of using <*> is nice for two, but not beautiful enough if I have to write ((((((v1,v2), v3), v4), v5), v6) <-- p1 <*> p2 <*> p3 <*> ... <*> p6. Any good trick to write (v1, v2, v3, v4, v5, ..., vn) <-- p1 <*> p2 <*> .. <*> pn ? I am afraid I have to use another CamlP4 trick here... Jun