summaryrefslogtreecommitdiff log msg author committer range
blob: 5536772f94bb95a88ca6bcd46edbee1864cd18c1 (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 ``` ``````module Main where import Control.Monad.Eff import Debug.Trace foreign import data Assert :: ! foreign import assert """ function assert(x) { return function(desc) { return function() { if (!x) throw new Error('assertion (' + desc + ') failed'); return {}; }; }; } """ :: forall e. Boolean -> String -> Eff (assert :: Assert | e) Unit bug :: Number -> Number -> Number bug a b = 0 - (a - b) foreign import explode """ function explode() { throw new Error('Assertion failed!'); } """ :: forall eff a. Eff eff a main = do assert (bug 0 2 == 2) "bug 0 2 == 2" assert (0 - (0 - 2) == 2) "0 - (0 - 2) == 2" assert (0 - (0 + 2) == -2) "0 - (0 + 2) == -2" assert (6 / (3 * 2) == 1) "6 / (3 * 2) == 1" assert ((6 / 3) * 2 == 4) "(6 / 3) * 2 == 4" assert (not (1 < 0) == true) "not (1 < 0) == true" assert (not ((negate 1) < 0) == false) "not ((negate 1) < 0) == false" assert (negate (1 + 10) == -11) "negate (1 + 10) == -11" assert (2 * 3 / 4 == 1.5) "2 * 3 / 4 == 1.5" assert (1 * 2 * 3 * 4 * 5 / 6 == 20) "1 * 2 * 3 * 4 * 5 / 6 == 20" assert (1 + 10 - 5 == 6) "1 + 10 - 5 == 6" assert (1 + 10 * 5 == 51) "1 + 10 * 5 == 51" assert (10 * 5 - 1 == 49) "10 * 5 - 1 == 49" trace "Success!" ``````