Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Alex Baretta <alex@barettadeit.com>
To: Ocaml <caml-list@inria.fr>, Luca Pascali <luca@barettadeit.com>,
	Ernesto Ferrari <ernesto@barettadeit.com>,
	Domenico Cosentino <dome@barettadeit.com>
Cc: Gerd Stolpmann <info@gerd-stolpmann.de>
Subject: Dummy polymorphic constructors
Date: Thu, 16 Dec 2004 20:22:57 +0100	[thread overview]
Message-ID: <41C1E091.1040508@barettadeit.com> (raw)

Currently ocaml does not support empty polymorphic variant sum types. 
Say, I cannot write the following.

type empty = [ ]

This fails due to a syntax error rather than a typing error, which is a 
sensible, given that the type expression I have written is actually 
perfectly meaningful.

Is there a design decision behind this, or have the Caml breeders simply 
overlooked the potential need for empty types?

What do you guys think of the following patch?

Alex

diff -Naur stable/parsing/parser.mly patched/parsing/parser.mly
--- stable/parsing/parser.mly   2004-12-16 20:15:53.000000000 +0100
+++ patched/parsing/parser.mly  2004-12-16 20:16:16.000000000 +0100
@@ -10,6 +10,9 @@
  /*                                                                     */
  /***********************************************************************/

+/* Patched by Baretta DE&IT to add support for empty variant types */
+
+
  /* $Id: parser.mly,v 1.120 2004/05/19 12:15:19 doligez Exp $ */

  /* The parser definition */
@@ -1285,8 +1288,8 @@
        { mktyp(Ptyp_variant([$2], true, None)) }
    | LBRACKET BAR row_field_list RBRACKET
        { mktyp(Ptyp_variant(List.rev $3, true, None)) }
-  | LBRACKET row_field BAR row_field_list RBRACKET
-      { mktyp(Ptyp_variant($2 :: List.rev $4, true, None)) }
+  | LBRACKET row_field_list RBRACKET
+      { mktyp(Ptyp_variant(List.rev $2, true, None)) }
    | LBRACKETGREATER opt_bar row_field_list RBRACKET
        { mktyp(Ptyp_variant(List.rev $3, false, None)) }
    | LBRACKETGREATER RBRACKET
@@ -1297,7 +1300,8 @@
        { mktyp(Ptyp_variant(List.rev $3, true, Some (List.rev $5))) }
  ;
  row_field_list:
-    row_field                                   { [$1] }
+    /* empty */                                 { [] }
+  | row_field                                   { [$1] }
    | row_field_list BAR row_field                { $3 :: $1 }
  ;
  row_field:

-- 
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL

tel. +39 02 370 111 55
fax. +39 02 370 111 54

Our technology:

The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>


             reply	other threads:[~2004-12-16 19:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-16 19:22 Alex Baretta [this message]
2004-12-16 22:38 ` [Caml-list] " John Prevost
2004-12-17  7:42   ` Alex Baretta
2004-12-17  7:59   ` skaller
2004-12-17  1:10 ` Jacques Garrigue
2004-12-17  9:03   ` 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=41C1E091.1040508@barettadeit.com \
    --to=alex@barettadeit.com \
    --cc=caml-list@inria.fr \
    --cc=dome@barettadeit.com \
    --cc=ernesto@barettadeit.com \
    --cc=info@gerd-stolpmann.de \
    --cc=luca@barettadeit.com \
    /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