From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 3F2C7D460 for ; Tue, 8 Nov 2005 14:29:10 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jA8DT9li001122 for ; Tue, 8 Nov 2005 14:29:09 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA06165 for ; Tue, 8 Nov 2005 14:29:09 +0100 (MET) Received: from pih-relay04.plus.net (pih-relay04.plus.net [212.159.14.131]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jA8DT8bm001117 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Tue, 8 Nov 2005 14:29:08 +0100 Received: from [80.229.56.224] (helo=chetara) by pih-relay04.plus.net with esmtp (Exim) id 1EZTX9-0004pM-HO for caml-list@inria.fr; Tue, 08 Nov 2005 13:29:07 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. 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 User-Agent: KMail/1.8.2 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511081324.32311.jon@ffconsultancy.com> X-Miltered: at nez-perce with ID 4370A825.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4370A824.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocamlyacc:01 expr:01 parser:01 ocamlyacc:01 minor:01 grammar:01 expr:01 recursive:01 ocaml:01 ocaml:01 frog:98 polymorphic:01 polymorphic:01 define:01 monomorphic:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 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 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