2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[HsLit]{Abstract syntax: source-language literals}
9 #include "HsVersions.h"
12 import Ratio ( Rational )
15 %************************************************************************
17 \subsection[HsLit]{Literals}
19 %************************************************************************
24 = HsChar Int -- characters
25 | HsCharPrim Int -- unboxed char literals
26 | HsString FAST_STRING -- strings
27 | HsStringPrim FAST_STRING -- packed string
29 | HsInt Integer -- integer-looking literals
30 | HsFrac Rational -- frac-looking literals
31 -- Up through dict-simplification, HsInt and HsFrac simply
32 -- mean the literal was integral- or fractional-looking; i.e.,
33 -- whether it had an explicit decimal-point in it. *After*
34 -- dict-simplification, they mean (boxed) "Integer" and
35 -- "Rational" [Ratio Integer], respectively.
37 -- Dict-simplification tries to replace such lits w/ more
38 -- specific ones, using the unboxed variants that follow...
39 | HsIntPrim Integer -- unboxed Int literals
40 | HsFloatPrim Rational -- unboxed Float literals
41 | HsDoublePrim Rational -- unboxed Double literals
43 | HsLitLit FAST_STRING -- to pass ``literal literals'' through to C
44 -- also: "overloaded" type; but
45 -- must resolve to boxed-primitive!
50 ToDo: an improved Eq instance JJQC 30-Nov-1997
53 negLiteral (HsInt i) = HsInt (-i)
54 negLiteral (HsFrac f) = HsFrac (-f)
58 instance Outputable HsLit where
59 -- Use "show" because it puts in appropriate escapes
60 ppr (HsChar c) = pprHsChar c
61 ppr (HsCharPrim c) = pprHsChar c <> char '#'
62 ppr (HsString s) = pprHsString s
63 ppr (HsStringPrim s) = pprHsString s <> char '#'
64 ppr (HsInt i) = integer i
65 ppr (HsFrac f) = rational f
66 ppr (HsFloatPrim f) = rational f <> char '#'
67 ppr (HsDoublePrim d) = rational d <> text "##"
68 ppr (HsIntPrim i) = integer i <> char '#'
69 ppr (HsLitLit s) = hcat [text "``", ptext s, text "''"]