Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@inria.fr
Subject: ocamlyacc: e - the start symbol expr has a polymorphic type
Date: Tue, 8 Nov 2005 13:24:31 +0000	[thread overview]
Message-ID: <200511081324.32311.jon@ffconsultancy.com> (raw)


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


             reply	other threads:[~2005-11-08 13:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-08 13:24 Jon Harrop [this message]
2005-11-09 12:26 ` [Caml-list] " Jacques Garrigue
2005-11-09 12:39   ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200511081324.32311.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox