caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jun Furuse <jun.furuse@gmail.com>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] [ANN] Planck: a small monadic parser combinator library for OCaml
Date: Mon, 6 Jun 2011 15:42:56 +0900	[thread overview]
Message-ID: <BANLkTin9SQ_kzCzA8AxgiX6-R-si_CHbOQ@mail.gmail.com> (raw)
In-Reply-To: <BANLkTimCRGWDeGiEwDYBiQ+Rf5VFEGNWvQ@mail.gmail.com>

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

      reply	other threads:[~2011-06-06  6:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-28  2:11 Jun Furuse
2011-05-29  9:14 ` Gabriel Scherer
2011-06-06  6:42   ` Jun Furuse [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTin9SQ_kzCzA8AxgiX6-R-si_CHbOQ@mail.gmail.com \
    --to=jun.furuse@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=gabriel.scherer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).