summaryrefslogtreecommitdiff
path: root/compiler/deSugar/Check.lhs
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2008-05-06 10:25:51 +0000
committersimonpj@microsoft.com <unknown>2008-05-06 10:25:51 +0000
commitecdaf6bc29d23bd704df8c65442ee08032a585fc (patch)
tree73ebcd573eb5e273caae6fdfe75a1ca4aba2c2a1 /compiler/deSugar/Check.lhs
parent63a69b6790c0df41533c572bb53bc048efd48ff9 (diff)
downloadhaskell-ecdaf6bc29d23bd704df8c65442ee08032a585fc.tar.gz
Fix Trac #2246; overhaul handling of overloaded literals
The real work of fixing Trac #2246 is to use shortCutLit in MatchLit.dsOverLit, so that type information discovered late in the day by the type checker can still be exploited during desugaring. However, as usual I found myself doing some refactoring along the way, to tidy up the handling of overloaded literals. The main change is to split HsOverLit into a record, which in turn uses a sum type for the three variants. This makes the code significantly more modular. data HsOverLit id = OverLit { ol_val :: OverLitVal, ol_rebindable :: Bool, -- True <=> rebindable syntax -- False <=> standard syntax ol_witness :: SyntaxExpr id, -- Note [Overloaded literal witnesses] ol_type :: PostTcType } data OverLitVal = HsIntegral !Integer -- Integer-looking literals; | HsFractional !Rational -- Frac-looking literals | HsIsString !FastString -- String-looking literals
Diffstat (limited to 'compiler/deSugar/Check.lhs')
-rw-r--r--compiler/deSugar/Check.lhs10
1 files changed, 5 insertions, 5 deletions
diff --git a/compiler/deSugar/Check.lhs b/compiler/deSugar/Check.lhs
index 75186feecb..c5b13eb2d3 100644
--- a/compiler/deSugar/Check.lhs
+++ b/compiler/deSugar/Check.lhs
@@ -433,11 +433,11 @@ get_lit :: Pat id -> Maybe HsLit
-- Get a representative HsLit to stand for the OverLit
-- It doesn't matter which one, because they will only be compared
-- with other HsLits gotten in the same way
-get_lit (LitPat lit) = Just lit
-get_lit (NPat (HsIntegral i _ _) mb _) = Just (HsIntPrim (mb_neg mb i))
-get_lit (NPat (HsFractional f _ _) mb _) = Just (HsFloatPrim (mb_neg mb f))
-get_lit (NPat (HsIsString s _ _) _ _) = Just (HsStringPrim s)
-get_lit _ = Nothing
+get_lit (LitPat lit) = Just lit
+get_lit (NPat (OverLit { ol_val = HsIntegral i}) mb _) = Just (HsIntPrim (mb_neg mb i))
+get_lit (NPat (OverLit { ol_val = HsFractional f }) mb _) = Just (HsFloatPrim (mb_neg mb f))
+get_lit (NPat (OverLit { ol_val = HsIsString s }) _ _) = Just (HsStringPrim s)
+get_lit _ = Nothing
mb_neg :: Num a => Maybe b -> a -> a
mb_neg Nothing v = v