Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* ocamlyacc: e - the start symbol expr has a polymorphic type
@ 2005-11-08 13:24 Jon Harrop
  2005-11-09 12:26 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 3+ messages in thread
From: Jon Harrop @ 2005-11-08 13:24 UTC (permalink / raw)
  To: caml-list


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-11-09 12:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-08 13:24 ocamlyacc: e - the start symbol expr has a polymorphic type Jon Harrop
2005-11-09 12:26 ` [Caml-list] " Jacques Garrigue
2005-11-09 12:39   ` skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox