Version française
Home     About     Download     Resources     Contact us    
Browse thread
Dummy polymorphic constructors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alex Baretta <alex@b...>
Subject: Dummy polymorphic constructors
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/>