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: Jon Harrop <jon@f...>
Subject: ocamlyacc: e - the start symbol expr has a polymorphic type

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, if I give the type an alias:

  type expr = [`Num of float | `Op2 of [`Plus|`Times] * 'a * 'a] as 'a

and use:

  %type <expr> expr

then ocamlyacc is happy.

Am I missing something? Is there a fundamental problem with trying to 
determine when a recursive polymorphic variant is monomorphic? Why does 
giving the type a name make a difference?

PS: This example is for my new pages on OCaml:

  http://www.ffconsultancy.com/free/ocaml/

Let me know what you think.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists