caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Leo White <lpw25@cam.ac.uk>
To: "Christoph Höger" <christoph.hoeger@tu-berlin.de>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] recursive values of abstract types, aka Batteries ParserCo
Date: Sun, 24 Aug 2014 16:48:33 +0100	[thread overview]
Message-ID: <87k35x6g8e.fsf@study.localdomain> (raw)
In-Reply-To: <53F49BAE.40901@tu-berlin.de> ("Christoph \=\?utf-8\?Q\?H\=C3\=B6ge\?\= \=\?utf-8\?Q\?r\=22's\?\= message of "Wed, 20 Aug 2014 14:59:26 +0200")

> I wanted to parse a small lambda-calculus in OCaml and had batteries
> already as a dependency. Batteries comes with ParserCo, a small parser
> combinator library. Since I did not want to complicate things further,
> I decided to stick with it and avoid any parser generator. Using a
> monadic combinator library for a scannerless parser should be a
> relatively simple exercise, right?
>
> Unfortunately, it seems that ParserCo only exposes an abstract type:
>
> type ('a, 'b, 'c) t
>
> which is, of course, a function:
>
> type ('a, 'b, 'c) t = ('a, 'c) Source.t -> ('a, 'b, 'c) result
>
> This prevents me from defining any recursive parsers, since OCaml
> won't let me let-rec a value of an abstract function type. I cannot do
> eta-expansion, because the type is abstract, and I also do not have a
> type constructor at hand.
>
> How does one handle such cases in OCaml? Does this really mean, you
> cannot have recursive values of abstract function types?

Hi Christoph,

I haven't used ParserCo (or even looked at the documentation), but the
'lazy' keyword has a relaxed notion of what can be defined recursively,
so creating a recusive `('a, 'b, 'c) t Lazy.t` and then forcing it may
well solve your problem.

Regards,

Leo

      reply	other threads:[~2014-08-24 15:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-20 12:59 Christoph Höger
2014-08-24 15:48 ` Leo White [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=87k35x6g8e.fsf@study.localdomain \
    --to=lpw25@cam.ac.uk \
    --cc=caml-list@inria.fr \
    --cc=christoph.hoeger@tu-berlin.de \
    /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).