Version française
Home     About     Download     Resources     Contact us    
Browse thread
ocamlyacc: e - the start symbol expr has a polymorphic type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] ocamlyacc: e - the start symbol expr has a polymorphic type
From: Jon Harrop <jon@ffconsultancy.com>

> I'm just trying to write an example parser using ocamlyacc and have come 
> across a minor irritation.
> 
> The example is a calculator and, in the interests of brevity, I'd like to 
> return the AST as a polymorphic variant. However, if I define the return type 
> from the grammar rule as:
> 
>   %type <[`Num of float | `Op2 of [`Plus|`Times] * 'a * 'a] as 'a> expr
> 
> I get the error:
> 
>   ocamlyacc: e - the start symbol expr has a polymorphic type
> 
> This type certainly contains the type variable 'a but I'm not sure
> I'd call it polymorphic.

Indeed, it is not.
But if you look at ocamlyacc's source, you will realize this is a C
program, which was derived from old BSD yacc (I believe.)
Difficult to expect it to understand the whole grammar of types, and
it is better to be on the safe side.
Note that a pure ocaml yacc replacement is in preparation, which might
be able to solve such problems.

Jacques Garrigue