summaryrefslogtreecommitdiff
path: root/testsuite/tests/parser/should_run/readRun001.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/parser/should_run/readRun001.hs')
-rw-r--r--testsuite/tests/parser/should_run/readRun001.hs57
1 files changed, 57 insertions, 0 deletions
diff --git a/testsuite/tests/parser/should_run/readRun001.hs b/testsuite/tests/parser/should_run/readRun001.hs
new file mode 100644
index 0000000000..d80f2adb7c
--- /dev/null
+++ b/testsuite/tests/parser/should_run/readRun001.hs
@@ -0,0 +1,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
+