[project @ 1999-06-15 10:20:50 by simonmar]
authorsimonmar <unknown>
Tue, 15 Jun 1999 10:20:50 +0000 (10:20 +0000)
committersimonmar <unknown>
Tue, 15 Jun 1999 10:20:50 +0000 (10:20 +0000)
Allow the syntax C{} for building an unlabelled constructor C and
setting all of C's fields to bottom.  The Haskell report is a bit
vague on whether this is legal, but it turns out to be quite easy to
support.

ghc/compiler/deSugar/DsExpr.lhs

index 2380384..095e7ce 100644 (file)
@@ -457,9 +457,12 @@ For record construction we do this (assuming T has three arguments)
 recConErr then converts its arugment string into a proper message
 before printing it as
 
-       M.lhs, line 230: missing field op1 was evaluated
+       M.lhs, line 230: Missing field in record construction op1
 
 
+We also handle C{} as valid construction syntax for an unlabelled
+constructor C, setting all of C's fields to bottom.
+
 \begin{code}
 dsExpr (RecordConOut data_con con_expr rbinds)
   = dsExpr con_expr    `thenDs` \ con_expr' ->
@@ -472,8 +475,16 @@ dsExpr (RecordConOut data_con con_expr rbinds)
              (rhs:rhss) -> ASSERT( null rhss )
                            dsExpr rhs
              []         -> mkErrorAppDs rEC_CON_ERROR_ID arg_ty (showSDoc (ppr lbl))
+       unlabelled_bottom arg_ty = mkErrorAppDs rEC_CON_ERROR_ID arg_ty ""
+
+       labels = dataConFieldLabels data_con
     in
-    mapDs mk_arg (zipEqual "dsExpr:RecordCon" arg_tys (dataConFieldLabels data_con)) `thenDs` \ con_args ->
+
+    (if null labels
+       then mapDs unlabelled_bottom arg_tys
+       else mapDs mk_arg (zipEqual "dsExpr:RecordCon" arg_tys labels))
+       `thenDs` \ con_args ->
+
     returnDs (mkApps con_expr' con_args)
 \end{code}