- = HsIntegral !Integer (SyntaxExpr id) PostTcType -- Integer-looking literals;
- | HsFractional !Rational (SyntaxExpr id) PostTcType -- Frac-looking literals
- | HsIsString !FastString (SyntaxExpr id) PostTcType -- String-looking literals
- -- Before type checking, the SyntaxExpr is 'fromInteger' or 'fromRational'
- -- After type checking, it is (fromInteger 3) or lit_78; that is,
- -- the expression that should replace the literal.
- -- This is unusual, because we're replacing 'fromInteger' with a call
- -- to fromInteger. Reason: it allows commoning up of the fromInteger
- -- calls, which wouldn't be possible if the desguarar made the application
- --
- -- The PostTcType in each branch records the type the overload literal is
- -- found to have.
-
-overLitExpr :: HsOverLit id -> SyntaxExpr id
-overLitExpr (HsIntegral _ e _) = e
-overLitExpr (HsFractional _ e _) = e
-overLitExpr (HsIsString _ e _) = e
-
-overLitType :: HsOverLit id -> PostTcType
-overLitType (HsIntegral _ _ t) = t
-overLitType (HsFractional _ _ t) = t
-overLitType (HsIsString _ _ t) = t
+ = OverLit {
+ ol_val :: OverLitVal,
+ ol_rebindable :: Bool, -- True <=> rebindable syntax
+ -- False <=> standard syntax
+ ol_witness :: SyntaxExpr id, -- Note [Overloaded literal witnesses]
+ ol_type :: PostTcType }
+ deriving (Data, Typeable)
+
+data OverLitVal
+ = HsIntegral !Integer -- Integer-looking literals;
+ | HsFractional !Rational -- Frac-looking literals
+ | HsIsString !FastString -- String-looking literals
+ deriving (Data, Typeable)
+
+overLitType :: HsOverLit a -> Type
+overLitType = ol_type
+\end{code}
+
+Note [Overloaded literal witnesses]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+*Before* type checking, the SyntaxExpr in an HsOverLit is the
+name of the coercion function, 'fromInteger' or 'fromRational'.
+*After* type checking, it is a witness for the literal, such as
+ (fromInteger 3) or lit_78
+This witness should replace the literal.
+
+This dual role is unusual, because we're replacing 'fromInteger' with
+a call to fromInteger. Reason: it allows commoning up of the fromInteger
+calls, which wouldn't be possible if the desguarar made the application