blob: d80f2adb7c1a5fe6d1f8d59dfc861c22ab96e385 (
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
-- !!! Haskell-98 prefix negate operator
-- Make sure the parsing is actually the correct
-- one by running this after it's compiled.
negatedExpression = - (3 + 4)
negatedTightlyBinding = -3^4
negatedNonSection = (- 3)
negatedNonSectionWithHighPrecedenceOp =
let { f = (+); infix 9 `f` } in ( -3 `f` 4 )
negatedNonSectionWithLowPrecedenceOp =
let { f = (+); infix 1 `f` } in ( -3 `f` 4 )
negatedRightHandSide =
-- This is actually not legal syntax: 3 * - 4
-- However, lower-precedence binary ops work.
-- (see H98 syntax for exp, or imagine it's because it
-- would parse differently as 3 * 0 - 4)
let { f = (+); infix 1 `f` } in ( 3 `f` - 4 )
subtractionNotNegation = 3 -4
negativePattern =
case -3 of { (- 3) ->
case -4 of { - 4 ->
True } }
-- not legal H98 syntax: case -4 of { _x @ -4 ->
-- (parentheses needed) case -5 of { ~ -5 ->
subtractionNotNegationPattern =
-- defines infix '-' (shadowing Prelude definition)
let { 3 -4 = True } in (3 - 4)
precedenceOfNegationCantBeChanged =
let { (-) = undefined; infix 9 - } in (- 3 * 4)
negationCantBeQualified =
(Prelude.-3) 4
main = do
print negatedExpression
print negatedTightlyBinding
print negatedNonSection
print negatedNonSectionWithHighPrecedenceOp
print negatedNonSectionWithLowPrecedenceOp
print negatedRightHandSide
print subtractionNotNegation
print negativePattern
print subtractionNotNegationPattern
print precedenceOfNegationCantBeChanged
print negationCantBeQualified
|