* [Caml-list] recursive values of abstract types, aka Batteries ParserCo
@ 2014-08-20 12:59 Christoph Höger
2014-08-24 15:48 ` Leo White
0 siblings, 1 reply; 2+ messages in thread
From: Christoph Höger @ 2014-08-20 12:59 UTC (permalink / raw)
To: caml users
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
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?
thanks,
Christoph
- --
Christoph Höger
Technische Universität Berlin
Fakultät IV - Elektrotechnik und Informatik
Übersetzerbau und Programmiersprachen
Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin
Tel.: +49 (30) 314-24890
E-Mail: christoph.hoeger@tu-berlin.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iEYEARECAAYFAlP0m64ACgkQhMBO4cVSGS+FcACdF2eqj5eN80oeRTghSnKDd9E+
80MAoL1DpqKfx5+UxJoLnUyZwpXQCibH
=Rw4X
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] recursive values of abstract types, aka Batteries ParserCo
2014-08-20 12:59 [Caml-list] recursive values of abstract types, aka Batteries ParserCo Christoph Höger
@ 2014-08-24 15:48 ` Leo White
0 siblings, 0 replies; 2+ messages in thread
From: Leo White @ 2014-08-24 15:48 UTC (permalink / raw)
To: Christoph Höger; +Cc: caml users
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-08-24 15:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-20 12:59 [Caml-list] recursive values of abstract types, aka Batteries ParserCo Christoph Höger
2014-08-24 15:48 ` Leo White
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox