caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Dummy polymorphic constructors
@ 2004-12-16 19:22 Alex Baretta
  2004-12-16 22:38 ` [Caml-list] " John Prevost
  2004-12-17  1:10 ` Jacques Garrigue
  0 siblings, 2 replies; 6+ messages in thread
From: Alex Baretta @ 2004-12-16 19:22 UTC (permalink / raw)
  To: Ocaml, Luca Pascali, Ernesto Ferrari, Domenico Cosentino; +Cc: Gerd Stolpmann

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/>


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

end of thread, other threads:[~2004-12-17  9:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-16 19:22 Dummy polymorphic constructors Alex Baretta
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

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).