From a0dd958a791a2decd383248a8c607bfee45dcf01 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 15 Jun 1999 10:20:50 +0000 Subject: [PATCH] [project @ 1999-06-15 10:20:50 by simonmar] 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 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ghc/compiler/deSugar/DsExpr.lhs b/ghc/compiler/deSugar/DsExpr.lhs index 2380384..095e7ce 100644 --- a/ghc/compiler/deSugar/DsExpr.lhs +++ b/ghc/compiler/deSugar/DsExpr.lhs @@ -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} -- 1.7.10.4