English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
types of ocamlyacc's entry points
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-11-03 (13:06)
From: Virgile Prevosto <virgile.prevosto@m...>
Subject: types of ocamlyacc's entry points
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
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) ->
%token <string> SPECIAL
%start main
%type <A.t> main
SPECIAL { A.from_string $1 }
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