caml-list - the Caml user's mailing list
 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

* Re: [Caml-list] ocamlyacc: e - the start symbol expr has a polymorphic type
  2005-11-08 13:24 ocamlyacc: e - the start symbol expr has a polymorphic type Jon Harrop
@ 2005-11-09 12:26 ` Jacques Garrigue
  2005-11-09 12:39   ` skaller
  0 siblings, 1 reply; 3+ messages in thread
From: Jacques Garrigue @ 2005-11-09 12:26 UTC (permalink / raw)
  To: jon; +Cc: caml-list

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


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

* Re: [Caml-list] ocamlyacc: e - the start symbol expr has a polymorphic type
  2005-11-09 12:26 ` [Caml-list] " Jacques Garrigue
@ 2005-11-09 12:39   ` skaller
  0 siblings, 0 replies; 3+ messages in thread
From: skaller @ 2005-11-09 12:39 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: jon, caml-list

On Wed, 2005-11-09 at 21:26 +0900, Jacques Garrigue wrote:

> Note that a pure ocaml yacc replacement is in preparation, which might
> be able to solve such problems.

Excellent news!!

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


^ 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;
as well as URLs for NNTP newsgroup(s).