Skip to content

Commit ff577ab

Browse files
committed
Merge pull request purescript#1018 from purescript/prelude-again
Further prelude updates
2 parents d1300e3 + 2fd349c commit ff577ab

File tree

7 files changed

+573
-481
lines changed

7 files changed

+573
-481
lines changed

examples/passing/Collatz.purs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
module Main where
22

3-
import Prelude
43
import Control.Monad.Eff
54
import Control.Monad.ST
65

6+
foreign import jsMod
7+
"""
8+
function jsMod(x) {
9+
return function (y) {
10+
return x % y;
11+
};
12+
}
13+
""" :: Number -> Number -> Number
14+
15+
infixl 7 %
16+
(%) = jsMod
17+
718
collatz :: Number -> Number
819
collatz n = runPure (runST (do
920
r <- newSTRef n

examples/passing/Guards.purs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
module Main where
22

3-
import Prelude
3+
foreign import jsMod
4+
"""
5+
function jsMod(x) {
6+
return function (y) {
7+
return x % y;
8+
};
9+
}
10+
""" :: Number -> Number -> Number
411

5-
collatz = \x -> case x of
6-
y | y % 2 == 0 -> y / 2
7-
y -> y * 3 + 1
12+
infixl 7 %
13+
(%) = jsMod
814

9-
-- Guards have access to current scope
10-
collatz2 = \x y -> case x of
11-
z | y > 0 -> z / 2
12-
z -> z * 3 + 1
15+
collatz = \x -> case x of
16+
y | y % 2 == 0 -> y / 2
17+
y -> y * 3 + 1
1318

14-
min :: forall a. (Ord a) => a -> a -> a
15-
min n m | n < m = n
16-
| otherwise = m
19+
-- Guards have access to current scope
20+
collatz2 = \x y -> case x of
21+
z | y > 0 -> z / 2
22+
z -> z * 3 + 1
1723

18-
max :: forall a. (Ord a) => a -> a -> a
19-
max n m = case unit of
20-
_ | m < n -> n
21-
| otherwise -> m
24+
min :: forall a. (Ord a) => a -> a -> a
25+
min n m | n < m = n
26+
| otherwise = m
2227

23-
testIndentation :: Number -> Number -> Number
24-
testIndentation x y | x > 0
25-
= x + y
26-
| otherwise
27-
= y - x
28+
max :: forall a. (Ord a) => a -> a -> a
29+
max n m = case unit of
30+
_ | m < n -> n
31+
| otherwise -> m
2832

29-
main = Debug.Trace.trace $ min "Done" "ZZZZ"
33+
testIndentation :: Number -> Number -> Number
34+
testIndentation x y | x > 0
35+
= x + y
36+
| otherwise
37+
= y - x
38+
39+
main = Debug.Trace.trace $ min "Done" "ZZZZ"

examples/passing/OperatorAssociativity.purs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ main = do
3535
assert (6 / (3 * 2) == 1) "6 / (3 * 2) == 1"
3636
assert ((6 / 3) * 2 == 4) "(6 / 3) * 2 == 4"
3737

38-
assert (6 % (2 * 2) == 2) "6 % (2 * 2) == 2"
39-
assert ((6 % 2) * 2 == 0) "(6 % 2) * 2 == 0"
40-
41-
assert (4 % (9 / 3) == 1) "4 % (9 / 3) == 1"
42-
assert ((4 % 9) / 2 == 2) "(4 % 9) / 2 == 2"
43-
4438
assert (not (1 < 0) == true) "not (1 < 0) == true"
4539
assert (not ((negate 1) < 0) == false) "not ((negate 1) < 0) == false"
4640

examples/passing/TopLevelCase.purs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
module Main where
22

3-
import Prelude
3+
foreign import jsMod
4+
"""
5+
function jsMod(x) {
6+
return function (y) {
7+
return x % y;
8+
};
9+
}
10+
""" :: Number -> Number -> Number
411

5-
gcd :: Number -> Number -> Number
6-
gcd 0 x = x
7-
gcd x 0 = x
8-
gcd x y | x > y = gcd (x % y) y
9-
gcd x y = gcd (y % x) x
12+
infixl 7 %
13+
(%) = jsMod
1014

11-
guardsTest (x:xs) | x > 0 = guardsTest xs
12-
guardsTest xs = xs
15+
gcd :: Number -> Number -> Number
16+
gcd 0 x = x
17+
gcd x 0 = x
18+
gcd x y | x > y = gcd (x % y) y
19+
gcd x y = gcd (y % x) x
1320

14-
data A = A
21+
guardsTest (x:xs) | x > 0 = guardsTest xs
22+
guardsTest xs = xs
1523

16-
parseTest A 0 = 0
24+
data A = A
1725

18-
main = Debug.Trace.trace "Done"
26+
parseTest A 0 = 0
27+
28+
main = Debug.Trace.trace "Done"

0 commit comments

Comments
 (0)