From: Virgile Prevosto <virgile.prevosto@m4x.org>
To: Caml list <caml-list@yquem.inria.fr>
Subject: types of ocamlyacc's entry points
Date: Wed, 3 Nov 2004 14:06:54 +0100 [thread overview]
Message-ID: <20041103140654.1098ccf1@mpiat2314> (raw)
Hello list,
I just ran into a problem while trying to parameterize an
ocamlyacc-generated parser by a custom parsing function. The
.mly file looked like:
-----------------------------
%token <string> SPECIAL
%start main
%type <(string -> 'a) -> 'a> main
%%
main:
SPECIAL { fun specialized_parser -> specialized_parser $1 }
%%
------------------------------
ocamlyacc complains: "e - the start symbol main has a polymorphic type".
It seems to me that this in contradiction with the manual, which says
that "The type part [of a %type directive] is an arbitrary Caml type
expression, except that all type constructor names must be fully
qualified". So, my first question is: Who is right, the documentation or
the implementation?
I suspect that this behavior is due to the bug #1583, which showed that
such types may lead to unsafe code, but I think that one or two line(s)
in the manual would be useful.
As a workaround, I've tried to wrap the parser in a functor (this was my
first intention in fact, as the custom parsing function should come
from a module):
-----------------------------
%{
module type Foo = sig type t val from_string: string -> t end
module ParseFormula =
functor (A: Foo) ->
struct
%}
%token <string> SPECIAL
%start main
%type <A.t> main
%%
main:
SPECIAL { A.from_string $1 }
%%
end
------------------------------
While looking like an ugly hack, this seems to work, except that the
generated .mli file is not correct (see feature wish #1703 and not a bug
#1886). I can ask make to remove it, but is there a cleaner way to
proceed (apart from using camlp4 or Stream) ?
Many thanks in advance,
--
E tutto per oggi, a la prossima volta
Virgile
reply other threads:[~2004-11-03 13:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20041103140654.1098ccf1@mpiat2314 \
--to=virgile.prevosto@m4x.org \
--cc=caml-list@yquem.inria.fr \
/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