blob: 7c8b0b0f193eb037f4188b4cae78bf32f46b7c04 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
{-# LANGUAGE LexicalNegation #-}
data FreeNum
= FromInteger Integer
| FromRational Rational
| Negate FreeNum
| FreeNum `Subtract` FreeNum
deriving (Show)
instance Num FreeNum where
fromInteger = FromInteger
negate = Negate
(-) = Subtract
instance Fractional FreeNum where
fromRational = FromRational
main = do
print (-123 :: FreeNum)
print (-1.5 :: FreeNum)
print (let x = 5 in -x :: FreeNum)
print (5-1 :: FreeNum) -- unlike NegativeLiterals, we parse it as (5 - 1), not (5 (-1))
print (-0 :: FreeNum)
print (-0.0 :: FreeNum)
print (-0o10 :: FreeNum)
print (-0x10 :: FreeNum)
|