git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
More Prelude work, run tests in nodejs
f1f9bc1Phil Freeman
examples/passing/ArrayType.purs+4
@@ -11,3 +11,7 @@ foreign import (:) :: forall a. a -> [a] -> [a]
11instance Functor [] where
11instance Functor [] where
12 fmap _ [] = []
12 fmap _ [] = []
13 fmap f (x:xs) = f x : fmap f xs
13 fmap f (x:xs) = f x : fmap f xs
14+
15+module Main where
16+
17+main = Trace.trace "Done"
examples/passing/Arrays.purs+5−1
@@ -1,4 +1,4 @@
1−module Arrays where
1+module ArraysTests where
2
2
3test1 = \arr -> arr !! 0 + arr !! 1
3test1 = \arr -> arr !! 0 + arr !! 1
4
4
@@ -18,4 +18,8 @@ test4 = \arr -> case arr of
18 [] -> 0
18 [] -> 0
19 [_] -> 0
19 [_] -> 0
20 x : y : xs -> x * y + test4 xs
20 x : y : xs -> x * y + test4 xs
21+
22+module Main where
23+
24+main = Trace.trace "Done"
21
25
examples/passing/Assign.purs+4
@@ -7,3 +7,7 @@ module Assign where
7 }
7 }
8 return x;
8 return x;
9 }
9 }
10+
11+module Main where
12+
13+main = Trace.trace "Done"
examples/passing/Auto.purs+4
@@ -9,3 +9,7 @@ module Auto where
9
9
10 run :: forall i o. SomeAuto i o -> i -> o
10 run :: forall i o. SomeAuto i o -> i -> o
11 run = \s i -> s (\a -> case a of Auto a -> a.step a.state i)
11 run = \s i -> s (\a -> case a of Auto a -> a.step a.state i)
12+
13+module Main where
14+
15+main = Trace.trace "Done"
examples/passing/Church.purs+4
@@ -12,3 +12,7 @@ module Church where
12 append = \l1 l2 r f -> l2 (l1 r f) f
12 append = \l1 l2 r f -> l2 (l1 r f) f
13
13
14 test = append (cons 1 empty) (cons 2 empty)
14 test = append (cons 1 empty) (cons 2 empty)
15+
16+module Main where
17+
18+main = Trace.trace "Done"
examples/passing/Conditional.purs+4
@@ -5,3 +5,7 @@ module Conditional where
5 bin = \x -> if x && !x then x else x
5 bin = \x -> if x && !x then x else x
6
6
7 not = \x -> if x then false else true
7 not = \x -> if x then false else true
8+
9+module Main where
10+
11+main = Trace.trace "Done"
examples/passing/Cons.purs+6−3
@@ -1,9 +1,12 @@
1module Cons where
1module Cons where
2
2
3− infixr 6 :
3+ import Prelude
4−
4+ import Arrays
5− foreign import (:) :: forall a. a -> [a] -> [a]
6
5
7 test1 = \xs -> 1 : xs
6 test1 = \xs -> 1 : xs
8
7
9 test2 = 1 : 2 : 3 : []
8 test2 = 1 : 2 : 3 : []
9+
10+module Main where
11+
12+main = Trace.trace "Done"
examples/passing/Console.purs+13−25
@@ -1,25 +1,13 @@
1−module Console where
1+module Main where
2−
2+
3− foreign import data IO :: * -> *
3+import Prelude
4−
4+import Eff
5− foreign import ret :: forall a. a -> IO a
5+import Trace
6−
6+
7− foreign import (>>=) :: forall a b. IO a -> (a -> IO b) -> IO b
7+replicateM_ :: forall m a. (Monad m) => Number -> m a -> m {}
8−
9− (*>) = \a -> \b -> a >>= \x -> b
10−
11− foreign import putStrLn :: String -> IO {}
12−
13− replicateM_ :: forall a. Number -> IO a -> IO {}
14− replicateM_ = \n -> \x ->
8+replicateM_ 0 _ = ret {}
15− {
9+replicateM_ n act = do
16− var io = ret {};
10+ act
17− for (i <- 0 until n)
11+ replicateM_ (n - 1) act
18− {
12+
19− io = x *> io;
20− }
21− return io;
22− }
23−
24− main = replicateM_ 10 (putStrLn "Hello World!")
13+main = replicateM_ 10 (trace "Hello World!")
25−
examples/passing/DataAndType.purs+4
@@ -3,3 +3,7 @@ module DataAndType where
3data A = A B
3data A = A B
4
4
5type B = A
5type B = A
6+
7+module Main where
8+
9+main = Trace.trace "Done"
examples/passing/DataImport.purs+4
@@ -10,3 +10,7 @@ test :: Test -> M1.Test
10test t = t
10test t = t
11
11
12testCtor = Test
12testCtor = Test
13+
14+module Main where
15+
16+main = Trace.trace "Done"
examples/passing/Do.purs+17−15
@@ -1,9 +1,3 @@
1−module Prelude where
2−
3−class Monad m where
4− ret :: forall a. a -> m a
5− (>>=) :: forall a b. m a -> (a -> m b) -> m b
6−
7module Do where
1module Do where
8
2
9import Prelude
3import Prelude
@@ -15,34 +9,38 @@ instance Prelude.Monad Maybe where
15 (>>=) Nothing _ = Nothing
9 (>>=) Nothing _ = Nothing
16 (>>=) (Just a) f = f a
10 (>>=) (Just a) f = f a
17
11
18−test1 = do Just "abc"
12+test1 = \ -> do
13+ Just "abc"
19
14
20−test3 = do
15+test2 = \ -> do
21 (x : _) <- Just [1, 2, 3]
16 (x : _) <- Just [1, 2, 3]
22 (y : _) <- Just [4, 5, 6]
17 (y : _) <- Just [4, 5, 6]
23 Just (x + y)
18 Just (x + y)
24
19
25−test4 = do
20+test3 = \ -> do
26 Just 1
21 Just 1
27 Nothing :: Maybe Number
22 Nothing :: Maybe Number
28 Just 2
23 Just 2
29
24
30−test5 mx my = do
25+test4 mx my = do
31 x <- mx
26 x <- mx
32 y <- my
27 y <- my
33 Just (x + y)
28 Just (x + y)
34
29
35−test6 mx my mz = do
30+test5 mx my mz = do
36 x <- mx
31 x <- mx
37 y <- my
32 y <- my
38 let sum = x + y
33 let sum = x + y
39 z <- mz
34 z <- mz
40 Just (z + sum)
35 Just (z + sum)
41
36
37+test6 mx = \ -> do
42−test7 mx = do let Just x = mx
38+ let Just x = mx
43− Just x
39+ Just x
44
40
45−test8 = do Just (do Just 1)
41+test8 = \ -> do
42+ Just (do
43+ Just 1)
46
44
47(<$>) :: forall a b. (a -> b) -> Maybe a -> Maybe b
45(<$>) :: forall a b. (a -> b) -> Maybe a -> Maybe b
48(<$>) f m = do
46(<$>) f m = do
@@ -62,4 +60,8 @@ forever a = do
62 a
60 a
63 forever a
61 forever a
64
62
65−test9 = foo <$> Just 1 <*> Just 2 <*> Just 3
63+test9 = \ -> foo <$> Just 1 <*> Just 2 <*> Just 3
64+
65+module Main where
66+
67+main = Trace.trace "Done"
examples/passing/Dollar.purs+4
@@ -10,3 +10,7 @@ id x = x
10test1 x = id $ id $ id $ id $ x
10test1 x = id $ id $ id $ id $ x
11
11
12test2 x = id id $ id x
12test2 x = id id $ id x
13+
14+module Main where
15+
16+main = Trace.trace "Done"
examples/passing/Eff.purs+18−62
@@ -1,71 +1,27 @@
1−module Prelude where
1+module TestEff where
2−
3−class Monad m where
4− ret :: forall a. a -> m a
5− (>>=) :: forall a b. m a -> (a -> m b) -> m b
6−
7−module Eff where
8
2
9import Prelude
3import Prelude
4+import Eff
5+import ST
6+import Errors
7+import Trace
10
8
11−-- Eff Monad
12−
13−foreign import data Eff :: # ! -> * -> *
14−
15−foreign import retEff :: forall e a. a -> Eff e a
16−
17−foreign import bindEff :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
18−
19−instance Prelude.Monad (Eff e) where
20− ret = retEff
21− (>>=) = bindEff
22−
23−type Pure a = forall e. Eff e a
24−
25−foreign import runPure :: forall a. Pure a -> a
26−
27−-- Errors
28−
29−foreign import data Error :: * -> !
30−
31−foreign import throwError :: forall e r. e -> Eff (err :: Error e | r) {}
32−
33−foreign import catchError :: forall e r a. (e -> Eff r a) -> Eff (err :: Error e | r) a -> Eff r a
34−
35−-- State
36−
37−foreign import data State :: * -> !
38−
39−foreign import get :: forall s r. Eff (state :: State s | r) s
40−
41−foreign import set :: forall s r. s -> Eff (state :: State s | r) {}
42−
43−foreign import runState :: forall s r a. s -> Eff (state :: State s | r) a -> Eff r { value :: a, state :: s }
44−
45−-- ST
46−
47−foreign import data ST :: * -> !
48−
49−foreign import data STRef :: * -> * -> *
50−
51−foreign import newSTRef :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
52−
53−foreign import readSTRef :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
54−
55−foreign import modifySTRef :: forall a h r. (a -> a) -> STRef h a -> Eff (st :: ST h | r) {}
56−
57−foreign import runST :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
58−
59−-- Tests
60−
61−test1 = runPure (runState 0 (catchError (\s -> ret 0)
9+test1 = catchError (\s -> ret 0)
62− (do s <- get
10+ (do trace "Testing"
63− throwError "Error!"
11+ throwError "Error!")
64− set (s + 1)
65− ret s)))
66
12
67test2 = runPure (runST (do
13test2 = runPure (runST (do
68 ref <- newSTRef 0
14 ref <- newSTRef 0
69 modifySTRef (\n -> n + 1) ref
15 modifySTRef (\n -> n + 1) ref
70 readSTRef ref))
16 readSTRef ref))
71
17
18+module Main where
19+
20+import Eff
21+import TestEff
22+import Global
23+
24+main = do
25+ n <- test1
26+ Trace.print n
27+ Trace.print test2
examples/passing/ExternData.purs+5−1
@@ -12,4 +12,8 @@ module ExternData where
12
12
13 foreign import prompt :: IO String
13 foreign import prompt :: IO String
14
14
15− main = prompt `bind` \s -> showMessage s
15+ main = \ -> prompt `bind` \s -> showMessage s
16+
17+module Main where
18+
19+main = Trace.trace "Done"
examples/passing/ExternRaw.purs+4
@@ -11,3 +11,7 @@ foreign import concat "function concat(xs) { \
11 \ return xs.concat(ys); \
11 \ return xs.concat(ys); \
12 \ };\
12 \ };\
13 \}" :: forall a. [a] -> [a] -> [a]
13 \}" :: forall a. [a] -> [a] -> [a]
14+
15+module Main where
16+
17+main = Trace.trace "Done"
examples/passing/FFI.purs+5−1
@@ -9,4 +9,8 @@ module FFIModuleTest where
9
9
10import FFI
10import FFI
11
11
12−baz = foo "test"
12+baz = \ -> foo "test"
13+
14+module Main where
15+
16+main = Trace.trace "Done"
examples/passing/Functions.purs+4
@@ -11,3 +11,7 @@ module Functions where
11 test5 = \(%%) -> 1 %% 2
11 test5 = \(%%) -> 1 %% 2
12
12
13 test6 = \((+++), (***)) -> 1 +++ 2 *** 3
13 test6 = \((+++), (***)) -> 1 +++ 2 *** 3
14+
15+module Main where
16+
17+main = Trace.trace "Done"
examples/passing/Guards.purs+4
@@ -8,3 +8,7 @@ module Guards where
8 collatz2 = \x y -> case x of
8 collatz2 = \x y -> case x of
9 z | y > 0 -> z / 2
9 z | y > 0 -> z / 2
10 z -> z * 3 + 1
10 z -> z * 3 + 1
11+
12+module Main where
13+
14+main = Trace.trace "Done"
examples/passing/IfThenElse.purs+4
@@ -34,3 +34,7 @@ module IfThenElse where
34 }
34 }
35 return y;
35 return y;
36 }
36 }
37+
38+module Main where
39+
40+main = Trace.trace "Done"
examples/passing/Import.purs+4
@@ -10,3 +10,7 @@ module M2 where
10 import M1
10 import M1
11
11
12 main = \() -> foo 42
12 main = \() -> foo 42
13+
14+module Main where
15+
16+main = Trace.trace "Done"
examples/passing/List.purs+3
@@ -18,4 +18,7 @@ module List where
18
18
19 flatten Nil = Nil
19 flatten Nil = Nil
20 flatten (Cons cons) = concat cons.head (flatten cons.tail)
20 flatten (Cons cons) = concat cons.head (flatten cons.tail)
21+
22+module Main where
21
23
24+main = Trace.trace "Done"
examples/passing/Match.purs+4
@@ -3,3 +3,7 @@ module Match where
3 data Foo a = Foo
3 data Foo a = Foo
4
4
5 foo = \f -> case f of Foo -> "foo"
5 foo = \f -> case f of Foo -> "foo"
6+
7+module Main where
8+
9+main = Trace.trace "Done"
examples/passing/Maybe.purs+9−9
@@ -1,11 +1,11 @@
1−module Maybe where
1+module Main where
2
2
3− data Maybe a = Nothing | Just a
3+import Prelude
4+import Maybe
4
5
5− maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
6+main = do
6− maybe b _ Nothing = b
7+ let test1 = fromMaybe $ do
7− maybe _ f (Just a) = f a
8+ a <- Just 1
8−
9+ b <- Just 2
9− fmap m f = maybe Nothing (\a -> Just (f a)) m
10+ ret (a + b)
10−
11+ Trace.trace "Done"
11− bind m f = maybe Nothing f m
examples/passing/Module.purs+4
@@ -18,3 +18,7 @@ module M2 where
18
18
19 match :: M1.Foo -> String
19 match :: M1.Foo -> String
20 match = \f -> case f of M1.Foo s -> s ++ "foo"
20 match = \f -> case f of M1.Foo s -> s ++ "foo"
21+
22+module Main where
23+
24+main = Trace.trace "Done"
examples/passing/ModuleDeps.purs+4
@@ -11,3 +11,7 @@ bar = M3.baz
11module M3 where
11module M3 where
12
12
13baz = 1
13baz = 1
14+
15+module Main where
16+
17+main = Trace.trace "Done"
examples/passing/Monad.purs+4
@@ -26,3 +26,7 @@ module Monad where
26 test1 = test id
26 test1 = test id
27
27
28 test2 = test maybe
28 test2 = test maybe
29+
30+module Main where
31+
32+main = Trace.trace "Done"
examples/passing/MutRec.purs+4
@@ -13,3 +13,7 @@ module MutRec where
13 evenToNumber (Even n) = oddToNumber n + 1
13 evenToNumber (Even n) = oddToNumber n + 1
14
14
15 oddToNumber (Odd n) = evenToNumber n + 1
15 oddToNumber (Odd n) = evenToNumber n + 1
16+
17+module Main where
18+
19+main = Trace.trace "Done"
examples/passing/NamedPatterns.purs+4
@@ -3,3 +3,7 @@ module NamedPatterns where
3 foo = \x -> case x of
3 foo = \x -> case x of
4 y@{ foo = "Foo" } -> y
4 y@{ foo = "Foo" } -> y
5 y -> y
5 y -> y
6+
7+module Main where
8+
9+main = Trace.trace "Done"
examples/passing/Nested.purs+4
@@ -3,3 +3,7 @@ module Nested where
3 data Extend r a = Extend { prev :: r a, next :: a }
3 data Extend r a = Extend { prev :: r a, next :: a }
4
4
5 data Matrix r a = Square (r (r a)) | Bigger (Matrix (Extend r) a)
5 data Matrix r a = Square (r (r a)) | Bigger (Matrix (Extend r) a)
6+
7+module Main where
8+
9+main = Trace.trace "Done"
examples/passing/ObjectUpdate.purs+4
@@ -14,3 +14,7 @@ module ObjectUpdate where
14 polyUpdate = \o -> o { foo = "Foo" }
14 polyUpdate = \o -> o { foo = "Foo" }
15
15
16 inferPolyUpdate = \o -> o { foo = "Foo" }
16 inferPolyUpdate = \o -> o { foo = "Foo" }
17+
18+module Main where
19+
20+main = Trace.trace "Done"
examples/passing/Objects.purs+4
@@ -12,3 +12,7 @@ module Objects where
12
12
13 typed :: { foo :: Number }
13 typed :: { foo :: Number }
14 typed = { foo: 0 }
14 typed = { foo: 0 }
15+
16+module Main where
17+
18+main = Trace.trace "Done"
examples/passing/OneConstructor.purs+4
@@ -3,3 +3,7 @@ module OneConstructor where
3data One a = One a
3data One a = One a
4
4
5one (One a) = a
5one (One a) = a
6+
7+module Main where
8+
9+main = Trace.trace "Done"
examples/passing/Operators.purs+26
@@ -44,3 +44,29 @@ module Operators2 where
44 test11 = [1, 2, 3] ... [4, 5, 6]
44 test11 = [1, 2, 3] ... [4, 5, 6]
45
45
46 test12 (<%>) a b = a <%> b
46 test12 (<%>) a b = a <%> b
47+
48+module Main where
49+
50+import Operators1
51+import Operators2
52+
53+import Prelude
54+import Eff
55+import Trace
56+import Global
57+import Arrays
58+
59+main = do
60+ print (test1 (1, 2, \x y -> x + y))
61+ print test2
62+ print test3
63+ print test4
64+ print test5
65+ print test6
66+ print test7
67+ print test8
68+ print test9
69+ print test10
70+ print test11
71+ print (test12 k 1 2)
72+
examples/passing/OptimizerBug.purs+4
@@ -3,3 +3,7 @@ module OptimizerBug where
3x = 1 + y
3x = 1 + y
4
4
5y = x
5y = x
6+
7+module Main where
8+
9+main = Trace.trace "Done"
examples/passing/Patterns.purs+3
@@ -23,3 +23,6 @@ module Patterns where
23 [x, y] | x > y -> true
23 [x, y] | x > y -> true
24 _ -> false
24 _ -> false
25
25
26+module Main where
27+
28+main = Trace.trace "Done"
examples/passing/Person.purs+4
@@ -7,3 +7,7 @@ module Person where
7 showPerson :: Person -> String
7 showPerson :: Person -> String
8 showPerson = \p -> case p of
8 showPerson = \p -> case p of
9 Person o -> o.name ++ ", aged " ++ itoa(o.age)
9 Person o -> o.name ++ ", aged " ++ itoa(o.age)
10+
11+module Main where
12+
13+main = Trace.trace "Done"
examples/passing/Rank2Data.purs+4
@@ -23,3 +23,7 @@ module Rank2Data where
23 two = succ zero
23 two = succ zero
24 four = add two two
24 four = add two two
25 fourNumber = runNat four
25 fourNumber = runNat four
26+
27+module Main where
28+
29+main = Trace.trace "Done"
examples/passing/Rank2Types.purs+5−1
@@ -9,7 +9,7 @@ module Rank2Types where
9
9
10 foreign import exampleST :: forall s. ST s Number
10 foreign import exampleST :: forall s. ST s Number
11
11
12− testST = runST exampleST
12+ testST = \ -> runST exampleST
13
13
14 foreign import push :: forall el. el -> [el] -> [el]
14 foreign import push :: forall el. el -> [el] -> [el]
15
15
@@ -17,3 +17,7 @@ module Rank2Types where
17 replicateM = \ret bind n m -> case n of
17 replicateM = \ret bind n m -> case n of
18 0 -> ret []
18 0 -> ret []
19 n -> bind m (\x -> bind (replicateM ret bind (n - 1) m) (\xs -> ret (push x xs)))
19 n -> bind m (\x -> bind (replicateM ret bind (n - 1) m) (\xs -> ret (push x xs)))
20+
21+module Main where
22+
23+main = Trace.trace "Done"
examples/passing/Recursion.purs+4
@@ -4,3 +4,7 @@ module Recursion where
4 0 -> 1
4 0 -> 1
5 1 -> 1
5 1 -> 1
6 n -> fib (n - 1) + fib (n - 2)
6 n -> fib (n - 1) + fib (n - 2)
7+
8+module Main where
9+
10+main = Trace.trace "Done"
examples/passing/RedefinedFixity.purs+4
@@ -12,3 +12,7 @@ module M3 where
12
12
13import M1
13import M1
14import M2
14import M2
15+
16+module Main where
17+
18+main = Trace.trace "Done"
examples/passing/TailCall.purs+3
@@ -7,4 +7,7 @@ loop x = loop (x + 1)
7
7
8notATailCall = \x ->
8notATailCall = \x ->
9 (\notATailCall -> notATailCall x) (\x -> x)
9 (\notATailCall -> notATailCall x) (\x -> x)
10+
11+module Main where
10
12
13+main = Trace.trace "Done"
examples/passing/TopLevelCase.purs+4
@@ -12,3 +12,7 @@ module TopLevelCase where
12 data A = A
12 data A = A
13
13
14 parseTest A 0 = 0
14 parseTest A 0 = 0
15+
16+module Main where
17+
18+main = Trace.trace "Done"
examples/passing/TypeClasses.purs+11−7
@@ -6,19 +6,19 @@ class Show a where
6instance Show String where
6instance Show String where
7 show s = s
7 show s = s
8
8
9−test1 = show "testing"
9+test1 = \ -> show "testing"
10
10
11f :: forall a. (TypeClasses.Show a) => a -> String
11f :: forall a. (TypeClasses.Show a) => a -> String
12f x = show x
12f x = show x
13
13
14−test2 = f "testing"
14+test2 = \ -> f "testing"
15
15
16data Data a = Data a
16data Data a = Data a
17
17
18instance (TypeClasses.Show a) => TypeClasses.Show (Data a) where
18instance (TypeClasses.Show a) => TypeClasses.Show (Data a) where
19 show (Data a) = "Data (" ++ show a ++ ")"
19 show (Data a) = "Data (" ++ show a ++ ")"
20
20
21−test3 = show (Data "testing")
21+test3 = \ -> show (Data "testing")
22
22
23class Monad m where
23class Monad m where
24 ret :: forall a. a -> m a
24 ret :: forall a. a -> m a
@@ -35,10 +35,10 @@ instance TypeClasses.Monad Maybe where
35 (>>=) Nothing _ = Nothing
35 (>>=) Nothing _ = Nothing
36 (>>=) (Just a) f = f a
36 (>>=) (Just a) f = f a
37
37
38−test4 :: forall m. (Monad m) => m Number
38+test4 :: forall m. (Monad m) => () -> m Number
39−test4 = ret 1
39+test4 = \ -> ret 1
40
40
41−test5 = Just 1 >>= \n -> ret (n + 1)
41+test5 = \ -> Just 1 >>= \n -> ret (n + 1)
42
42
43module TypeClasses2 where
43module TypeClasses2 where
44
44
@@ -48,5 +48,9 @@ instance (TypeClasses.Show a) => TypeClasses.Show [a] where
48 show [] = "[]"
48 show [] = "[]"
49 show (x:xs) = TypeClasses.show x ++ ", " ++ TypeClasses.show xs
49 show (x:xs) = TypeClasses.show x ++ ", " ++ TypeClasses.show xs
50
50
51−test6 = show ["testing"]
51+test6 = \ -> show ["testing"]
52+
53+module Main where
54+
55+main = Trace.trace "Done"
52
56
examples/passing/TypeDecl.purs+4
@@ -14,3 +14,7 @@ module TypeDecl where
14 }
14 }
15 return result;
15 return result;
16 }
16 }
17+
18+module Main where
19+
20+main = Trace.trace "Done"
examples/passing/TypeSynonyms.purs+13−2
@@ -27,7 +27,18 @@ module TypeSynonyms where
27 test1 :: forall a b c. Lens (Pair (Pair a b) c) a
27 test1 :: forall a b c. Lens (Pair (Pair a b) c) a
28 test1 = composeLenses fst fst
28 test1 = composeLenses fst fst
29
29
30+ import Arrays
31+
30− foreign import head :: forall a. Lens [a] a
32+ headLens :: forall a. Lens [a] a
33+ headLens =
34+ { get: \l -> head l
35+ , set: \l a -> case l of
36+ _:xs -> a : xs
37+ }
31
38
32 test2 :: forall a b c. Lens (Pair [Pair a b] c) a
39 test2 :: forall a b c. Lens (Pair [Pair a b] c) a
33− test2 = composeLenses fst (composeLenses head fst)
40+ test2 = composeLenses fst (composeLenses headLens fst)
41+
42+module Main where
43+
44+main = Trace.trace "Done"
examples/passing/iota.purs+4
@@ -5,3 +5,7 @@ module Iota where
5 k = \x -> \y -> x
5 k = \x -> \y -> x
6
6
7 iota = \x -> x s k
7 iota = \x -> x s k
8+
9+module Main where
10+
11+main = Trace.trace "Done"
examples/passing/s.purs+4
@@ -1,3 +1,7 @@
1module S where
1module S where
2
2
3 s = \x y z -> x z (y z)
3 s = \x y z -> x z (y z)
4+
5+module Main where
6+
7+main = Trace.trace "Done"
libraries/prelude/Makefiledeleted−3
@@ -1,3 +0,0 @@
1−all:
2− ../../dist/build/psc/psc --no-prelude prelude.purs -o all.js
3− cat prelude.js >> all.js
libraries/prelude/prelude.jsdeleted−42
@@ -1,42 +0,0 @@
1−// Arrays
2−
3−function indexOf(l) { return function (e) { return l.indexOf(e); }; }
4−function lastIndexOf(l) { return function (e) { return l.lastIndexOf(e); }; }
5−function concat(l1) { return function (l2) { return l1.concat(l2); }; }
6−function join(l) { return l.join(); }
7−function joinWith(l) { return function (s) { return l.join(s); }; }
8−function push(l) { return function (e) { var l1 = l.slice(); l1.push(e); return l1; }; }
9−function reverse(l) { var l1 = l.slice(); l1.reverse(); return l1; }
10−function shift(l) { var l1 = l.slice(); l1.shift(); return l1; }
11−function slice(s) { return function(e) { return function (l) { return l.slice(s, e); }; }; }
12−function sort(l) { var l1 = l.slice(); l.sort(); return l1; }
13−function splice(s) { return function(e) { return function(l1) { return function(l2) { return l2.splice(s, e, l1); }; }; }; }
14−
15−function charAt(i) { return function(s) { return s.charAt(i); }; }
16−function indexOfS(s1) { return function(s2) { return s2.indexOf(s2); }; }
17−function lastIndexOfS(s1) { return function(s2) { return s2.lastIndexOf(s2); }; }
18−function localeCompare(s1) { return function(s2) { return s1.localeCompare(s2); }; }
19−function replace(s1) { return function(s2) { return function(s3) { return s3.replace(s1, s2) }; }; }
20−function sliceS(st) { return function(e) { return function(s) { return s.slice(st, e); }; }; }
21−function split(sep) { return function(s) { return s.split(s); }; }
22−function substr(n1) { return function(n2) { return function(s) { return s.substr(n1, n2); }; }; }
23−function substring(n1) { return function(n2) { return function(s) { return s.substring(n1, n2); }; }; }
24−function toLower(s) { return s.toLower(); }
25−function toUpper(s) { return s.toUpper(); }
26−function trim(s) { return s.trim(); }
27−
28−function regex(s1) { return function(s2) { return new Regex(s1, s2); }; };
29−function test(r) { return function (s) { return r.test(s); }; };
30−function match(r) { return function (s) { return s.match(r); }; };
31−function replaceR(r) { return function(s1) { return function(s2) { return s2.replace(r, s1) }; }; }
32−function search(r) { return function (s) { return s.search(r); }; };
33−
34−var nan = NaN;
35−var infinity = Infinity;
36−function toExponential(n) { return n.toExponential(); }
37−function toFixed(d) { return function(n) { return n.toFixed(d); }; }
38−function toPrecision(d) { return function(n) { return n.toPrecision(d); }; }
39−function numberToString(n) { return n.toString(); }
40−
41−var math = Math;
42−
libraries/prelude/prelude.purs+288−83
@@ -49,8 +49,9 @@ module Maybe where
49 fromMaybe :: forall a. a -> Maybe a -> a
49 fromMaybe :: forall a. a -> Maybe a -> a
50 fromMaybe a = maybe a Prelude.id
50 fromMaybe a = maybe a Prelude.id
51
51
52− bindMaybe :: forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
52+ instance Prelude.Monad Maybe where
53+ ret = Just
53− bindMaybe m f = maybe Nothing f m
54+ (>>=) m f = maybe Nothing f m
54
55
55module Either where
56module Either where
56
57
@@ -60,11 +61,13 @@ module Either where
60 either f _ (Left a) = f a
61 either f _ (Left a) = f a
61 either _ g (Right b) = g b
62 either _ g (Right b) = g b
62
63
63− bindEither :: forall e a b. Either e a -> (a -> Either e b) -> Either e b
64+ instance Prelude.Monad (Either e) where
65+ ret = Right
64− bindEither = either (\e _ -> Left e) (\a f -> f a)
66+ (>>=) = either (\e _ -> Left e) (\a f -> f a)
65
67
66module Arrays where
68module Arrays where
67
69
70+ import Prelude
68 import Maybe
71 import Maybe
69
72
70 head :: forall a. [a] -> a
73 head :: forall a. [a] -> a
@@ -97,27 +100,77 @@ module Arrays where
97 \ return xs.length; \
100 \ return xs.length; \
98 \}" :: forall a. [a] -> Number
101 \}" :: forall a. [a] -> Number
99
102
103+ foreign import indexOf "function indexOf(l) {\
104+ \ return function (e) {\
105+ \ return l.indexOf(e);\
106+ \ };\
100− foreign import indexOf :: forall a. [a] -> a -> Number
107+ \}" :: forall a. [a] -> a -> Number
101−
108+
102− foreign import lastIndexOf :: forall a. [a] -> a -> Number
109+ foreign import lastIndexOf "function lastIndexOf(l) {\
103−
110+ \ return function (e) {\
111+ \ return l.lastIndexOf(e);\
112+ \ };\
113+ \}" :: forall a. [a] -> a -> Number
114+
104− foreign import concat :: forall a. [a] -> [a] -> [a]
115+ foreign import concat "function concat(l1) {\
105−
116+ \ return function (l2) {\
117+ \ return l1.concat(l2);\
118+ \ };\
119+ \}" :: forall a. [a] -> [a] -> [a]
120+
121+ foreign import join "function join(l) {\
122+ \ return l.join();\
106− foreign import join :: [String] -> String
123+ \}" :: [String] -> String
107−
124+
108− foreign import joinWith :: [String] -> String -> String
125+ foreign import joinWith "function joinWith(l) {\
109−
126+ \ return function (s) {\
110− foreign import push :: forall a. [a] -> a -> [a]
127+ \ return l.join(s);\
111−
128+ \ };\
129+ \}" :: [String] -> String -> String
130+
112− foreign import reverse :: forall a. [a] -> [a]
131+ foreign import push "function push(l) {\
113−
132+ \ return function (e) {\
133+ \ var l1 = l.slice();\
134+ \ l1.push(e); \
135+ \ return l1;\
136+ \ };\
137+ \}" :: forall a. [a] -> a -> [a]
138+
139+ foreign import reverse "function reverse(l) {\
140+ \ var l1 = l.slice();\
141+ \ l1.reverse(); \
142+ \ return l1;\
143+ \}" :: forall a. [a] -> [a]
144+
145+ foreign import shift "function shift(l) {\
146+ \ var l1 = l.slice();\
147+ \ l1.shift();\
148+ \ return l1;\
114− foreign import shift :: forall a. [a] -> [a]
149+ \}" :: forall a. [a] -> [a]
115−
150+
151+ foreign import slice "function slice(s) {\
152+ \ return function(e) {\
153+ \ return function (l) {\
154+ \ return l.slice(s, e);\
155+ \ };\
156+ \ };\
116− foreign import slice :: forall a. Number -> Number -> [a] -> [a]
157+ \}" :: forall a. Number -> Number -> [a] -> [a]
117−
158+
118− foreign import sort :: forall a. [a] -> [a]
159+ foreign import sort "function sort(l) {\
119−
160+ \ var l1 = l.slice();\
161+ \ l.sort();\
162+ \ return l1;\
163+ \}" :: forall a. [a] -> [a]
164+
165+ foreign import splice "function splice(s) {\
166+ \ return function(e) {\
167+ \ return function(l1) { \
168+ \ return function(l2) {\
169+ \ return l2.splice(s, e, l1);\
170+ \ }; \
171+ \ }; \
172+ \ };\
120− foreign import splice :: forall a. Number -> Number -> [a] -> [a] -> [a]
173+ \}":: forall a. Number -> Number -> [a] -> [a] -> [a]
121
174
122 infixr 6 :
175 infixr 6 :
123
176
@@ -158,6 +211,10 @@ module Arrays where
158 all _ [] = true
211 all _ [] = true
159 all p (a:as) = p a && all p as
212 all p (a:as) = p a && all p as
160
213
214+ instance (Prelude.Show a) => Prelude.Show [a] where
215+ show [] = "[]"
216+ show (x:xs) = show x ++ " : " ++ show xs
217+
161module Tuple where
218module Tuple where
162
219
163 import Arrays
220 import Arrays
@@ -187,57 +244,141 @@ module String where
187 \ return s.length;\
244 \ return s.length;\
188 \}" :: String -> Number
245 \}" :: String -> Number
189
246
247+ foreign import charAt "function charAt(i) {\
248+ \ return function(s) {\
249+ \ return s.charAt(i); \
250+ \ };\
190− foreign import charAt :: Number -> String -> String
251+ \}" :: Number -> String -> String
191−
252+
253+ foreign import indexOfS "function indexOfS(s1) {\
254+ \ return function(s2) {\
255+ \ return s2.indexOf(s2);\
256+ \ }; \
192− foreign import indexOfS :: String -> String -> Number
257+ \}" :: String -> String -> Number
193−
258+
259+ foreign import lastIndexOfS "function lastIndexOfS(s1) {\
260+ \ return function(s2) {\
261+ \ return s2.lastIndexOf(s2);\
262+ \ };\
194− foreign import lastIndexOfS :: String -> String -> Number
263+ \}" :: String -> String -> Number
195−
264+
265+ foreign import localeCompare "function localeCompare(s1) {\
266+ \ return function(s2) { \
267+ \ return s1.localeCompare(s2);\
268+ \ };\
196− foreign import localeCompare :: String -> String -> Number
269+ \}" :: String -> String -> Number
197−
270+
271+ foreign import replace "function replace(s1) {\
272+ \ return function(s2) {\
273+ \ return function(s3) {\
274+ \ return s3.replace(s1, s2);\
275+ \ };\
276+ \ };\
198− foreign import replace :: String -> String -> String -> String
277+ \}" :: String -> String -> String -> String
199−
278+
279+ foreign import sliceS "function sliceS(st) {\
280+ \ return function(e) {\
281+ \ return function(s) {\
282+ \ return s.slice(st, e);\
283+ \ };\
284+ \ };\
200− foreign import sliceS :: Number -> Number -> String -> String
285+ \}" :: Number -> Number -> String -> String
201−
286+
287+ foreign import split "function split(sep) {\
288+ \ return function(s) {\
289+ \ return s.split(s);\
290+ \ };\
202− foreign import split :: String -> String -> [String]
291+ \}" :: String -> String -> [String]
203−
292+
293+ foreign import substr "function substr(n1) {\
294+ \ return function(n2) {\
295+ \ return function(s) {\
296+ \ return s.substr(n1, n2);\
297+ \ };\
298+ \ };\
204− foreign import substr :: Number -> Number -> String -> String
299+ \}" :: Number -> Number -> String -> String
205−
300+
301+ foreign import substring "function substring(n1) {\
302+ \ return function(n2) {\
303+ \ return function(s) {\
304+ \ return s.substring(n1, n2);\
305+ \ };\
306+ \ };\
206− foreign import substring :: Number -> Number -> String -> String
307+ \}" :: Number -> Number -> String -> String
207−
308+
208− foreign import toLower :: String -> String
309+ foreign import toLower "function toLower(s) {\
209−
310+ \ return s.toLower();\
311+ \}" :: String -> String
312+
210− foreign import toUpper :: String -> String
313+ foreign import toUpper "function toUpper(s) {\
211−
314+ \ return s.toUpper();\
315+ \}" :: String -> String
316+
317+ foreign import trim "function trim(s) {\
318+ \ return s.trim();\
212− foreign import trim :: String -> String
319+ \}" :: String -> String
213
320
214module Regex where
321module Regex where
215
322
216 foreign import data Regex :: *
323 foreign import data Regex :: *
217
324
325+ foreign import regex "function regex(s1) {\
326+ \ return function(s2) {\
327+ \ return new Regex(s1, s2);\
328+ \ };\
218− foreign import regex :: String -> String -> Regex
329+ \}" :: String -> String -> Regex
219−
330+
331+ foreign import test "function test(r) {\
332+ \ return function (s) { \
333+ \ return r.test(s);\
334+ \ };\
220− foreign import test :: Regex -> String -> Boolean
335+ \}" :: Regex -> String -> Boolean
221−
336+
337+ foreign import match "function match(r) {\
338+ \ return function (s) {\
339+ \ return s.match(r); \
340+ \ };\
222− foreign import match :: Regex -> String -> [String]
341+ \}" :: Regex -> String -> [String]
223−
342+
343+ foreign import replaceR "function replaceR(r) {\
344+ \ return function(s1) {\
345+ \ return function(s2) { \
346+ \ return s2.replace(r, s1);\
347+ \ };\
348+ \ };\
224− foreign import replaceR :: Regex -> String -> String -> String
349+ \}" :: Regex -> String -> String -> String
225−
350+
351+ foreign import search "function search(r) {\
352+ \ return function (s) {\
353+ \ return s.search(r);\
354+ \ };\
226− foreign import search :: Regex -> String -> Number
355+ \}" :: Regex -> String -> Number
227
356
228module Global where
357module Global where
229
358
230− foreign import nan :: Number
359+ foreign import nan "var nan = NaN;" :: Number
231
360
232− foreign import infinity :: Number
361+ foreign import infinity "var infinity = Infinity;" :: Number
233
362
234− foreign import toExponential :: Number -> String
363+ foreign import toExponential "function toExponential(n) {\
364+ \ return n.toExponential();\
365+ \}" :: Number -> String
235
366
367+ foreign import toFixed "function toFixed(d) {\
368+ \ return function(n) {\
369+ \ return n.toFixed(d);\
370+ \ };\
236− foreign import toFixed :: Number -> Number -> String
371+ \}" :: Number -> Number -> String
237
372
373+ foreign import toPrecision "function toPrecision(d) {\
374+ \ return function(n) {\
375+ \ return n.toPrecision(d);\
376+ \ };\
238− foreign import toPrecision :: Number -> Number -> String
377+ \}" :: Number -> Number -> String
239
378
240− foreign import numberToString :: Number -> String
379+ foreign import numberToString "function numberToString(n) {\
380+ \ return n.toString();\
381+ \}" :: Number -> String
241
382
242 foreign import isNaN :: Number -> Boolean
383 foreign import isNaN :: Number -> Boolean
243
384
@@ -255,6 +396,9 @@ module Global where
255
396
256 foreign import decodeURI :: String -> String
397 foreign import decodeURI :: String -> String
257
398
399+ instance Prelude.Show Number where
400+ show = numberToString
401+
258module Math where
402module Math where
259
403
260 type Math =
404 type Math =
@@ -277,19 +421,31 @@ module Math where
277 , tan :: Number -> Number
421 , tan :: Number -> Number
278 }
422 }
279
423
280− foreign import math :: Math
424+ foreign import math "var math = Math;" :: Math
281
425
282module Eff where
426module Eff where
283
427
284 foreign import data Eff :: # ! -> * -> *
428 foreign import data Eff :: # ! -> * -> *
285
429
286− foreign import retEff "function retEff(a) { return function() { return a; }; }" :: forall e a. a -> Eff e a
430+ foreign import retEff "function retEff(a) { \
431+ \ return function() { \
432+ \ return a; \
433+ \ }; \
434+ \}" :: forall e a. a -> Eff e a
287
435
288− foreign import bindEff "function bindEff(a) { return function(f) { return function() { return f(a())(); }; }; }" :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
436+ foreign import bindEff "function bindEff(a) { \
437+ \ return function(f) { \
438+ \ return function() { \
439+ \ return f(a())(); \
440+ \ }; \
441+ \ }; \
442+ \}" :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
289
443
290 type Pure a = forall e. Eff e a
444 type Pure a = forall e. Eff e a
291
445
292− foreign import runPure "function runPure(f) { return f(); }" :: forall a. Pure a -> a
446+ foreign import runPure "function runPure(f) { \
447+ \ return f(); \
448+ \}" :: forall a. Pure a -> a
293
449
294 instance Prelude.Monad (Eff e) where
450 instance Prelude.Monad (Eff e) where
295 ret = retEff
451 ret = retEff
@@ -301,9 +457,23 @@ module Errors where
301
457
302 foreign import data Error :: * -> !
458 foreign import data Error :: * -> !
303
459
304− foreign import throwError "function throwError(e) { return function() { throw e; }; }" :: forall a e r. e -> Eff (err :: Error e | r) a
460+ foreign import throwError "function throwError(e) { \
305−
461+ \ return function() { \
462+ \ throw e; \
463+ \ }; \
464+ \}" :: forall a e r. e -> Eff (err :: Error e | r) a
465+
306− foreign import catchError "function catchError(c) { return function(t) { return function() { try { return t(); } catch(e) { return c(e)(); } }; }; }" :: forall e r a. (e -> Eff r a) -> Eff (err :: Error e | r) a -> Eff r a
466+ foreign import catchError "function catchError(c) { \
467+ \ return function(t) { \
468+ \ return function() { \
469+ \ try { \
470+ \ return t(); \
471+ \ } catch(e) { \
472+ \ return c(e)(); \
473+ \ }\
474+ \ }; \
475+ \ }; \
476+ \}" :: forall e r a. (e -> Eff r a) -> Eff (err :: Error e | r) a -> Eff r a
307
477
308module IORef where
478module IORef where
309
479
@@ -313,11 +483,25 @@ module IORef where
313
483
314 foreign import data IORef :: * -> *
484 foreign import data IORef :: * -> *
315
485
486+ foreign import newIORef "function newIORef(val) {\
487+ \ return function () {\
488+ \ return { value: val };\
489+ \ };\
316− foreign import newIORef :: forall s r. s -> Eff (ref :: Ref | r) (IORef s)
490+ \}" :: forall s r. s -> Eff (ref :: Ref | r) (IORef s)
317−
491+
492+ foreign import readIORef "function readIORef(ref) {\
493+ \ return function() {\
494+ \ return ref.value;\
495+ \ };\
318− foreign import readIORef :: forall s r. IORef s -> Eff (ref :: Ref | r) s
496+ \}" :: forall s r. IORef s -> Eff (ref :: Ref | r) s
319−
497+
498+ foreign import writeIORef "function writeIORef(ref) {\
499+ \ return function(val) {\
500+ \ return function() {\
501+ \ ref.value = val;\
502+ \ };\
503+ \ };\
320− foreign import writeIORef :: forall s r. IORef s -> s -> Eff (ref :: Ref | r) {}
504+ \}" :: forall s r. IORef s -> s -> Eff (ref :: Ref | r) {}
321
505
322module Trace where
506module Trace where
323
507
@@ -326,7 +510,12 @@ module Trace where
326
510
327 foreign import data Trace :: !
511 foreign import data Trace :: !
328
512
329− foreign import trace "function trace(s) { return function() { console.log(s); return {}; }; }" :: forall r. String -> Eff (trace :: Trace | r) {}
513+ foreign import trace "function trace(s) { \
514+ \ return function() { \
515+ \ console.log(s); \
516+ \ return {}; \
517+ \ }; \
518+ \}" :: forall r. String -> Eff (trace :: Trace | r) {}
330
519
331 print :: forall a r. (Prelude.Show a) => a -> Eff (trace :: Trace | r) {}
520 print :: forall a r. (Prelude.Show a) => a -> Eff (trace :: Trace | r) {}
332 print o = trace (show o)
521 print o = trace (show o)
@@ -339,11 +528,27 @@ module ST where
339
528
340 foreign import data STRef :: * -> * -> *
529 foreign import data STRef :: * -> * -> *
341
530
531+ foreign import newSTRef "function newSTRef(val) {\
532+ \ return function () {\
533+ \ return { value: val };\
534+ \ };\
342− foreign import newSTRef :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
535+ \}" :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
343−
536+
537+ foreign import readSTRef "function readSTRef(ref) {\
538+ \ return function() {\
539+ \ return ref.value;\
540+ \ };\
344− foreign import readSTRef :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
541+ \}" :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
345−
542+
543+ foreign import modifySTRef "function modifySTRef(f) {\
544+ \ return function(ref) {\
545+ \ return function() {\
546+ \ ref.value = f(ref.value);\
547+ \ };\
548+ \ };\
346− foreign import modifySTRef :: forall a h r. (a -> a) -> STRef h a -> Eff (st :: ST h | r) {}
549+ \}" :: forall a h r. (a -> a) -> STRef h a -> Eff (st :: ST h | r) {}
347−
550+
551+ foreign import runST "function runST(f) {\
552+ \ return f;\
348− foreign import runST :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
553+ \}" :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
349
554
libraries/prelude/tests/.gitignorenew file+1
@@ -0,0 +1 @@
1+Eff.js
libraries/prelude/tests/Eff.purs+11−11
@@ -5,32 +5,32 @@ import Eff
5import Errors
5import Errors
6import Trace
6import Trace
7
7
8−test1 n = runPure $ catchError (\s -> eff do return 0) $ eff do
8+test1 n = runPure $ catchError (\s -> ret 0) $ do
9 case {} of
9 case {} of
10− _ | n > 10 -> eff do
10+ _ | n > 10 -> do
11 throwError "Error!"
11 throwError "Error!"
12− _ -> eff do return n
12+ _ -> ret n
13
13
14−test2 = eff do
14+test2 = do
15 trace "Hello World"
15 trace "Hello World"
16 throwError "Error!"
16 throwError "Error!"
17
17
18−test3 n = catchError (\s -> eff do return 0) $ eff do
18+test3 n = catchError (\s -> ret 0) $ do
19 case {} of
19 case {} of
20− _ | n > 10 -> eff do
20+ _ | n > 10 -> do
21 trace "n > 10"
21 trace "n > 10"
22 throwError "Error!"
22 throwError "Error!"
23− _ -> eff do return n
23+ _ -> ret n
24
24
25−test4 = eff do
25+test4 = do
26 trace "Hello World!"
26 trace "Hello World!"
27− return 0
27+ ret 0
28
28
29−test5 = eff do
29+test5 = do
30 trace "Hello World!"
30 trace "Hello World!"
31 test5
31 test5
32
32
33−test6 s = eff do
33+test6 s = do
34 trace s
34 trace s
35 test6 (s ++ " test")
35 test6 (s ++ " test")
36
36
libraries/prelude/tests/build.shnew file+2
@@ -0,0 +1,2 @@
1+psc ../prelude.purs Eff.purs --magic-do --run-main --no-prelude -o Eff.js
2+
purescript.cabal+1−1
@@ -89,7 +89,7 @@ executable psci
89test-suite tests
89test-suite tests
90 build-depends: base >=4 && <5, containers -any, directory -any,
90 build-depends: base >=4 && <5, containers -any, directory -any,
91 filepath -any, mtl -any, parsec -any, purescript -any, syb -any,
91 filepath -any, mtl -any, parsec -any, purescript -any, syb -any,
92− transformers -any, utf8-string -any
92+ transformers -any, utf8-string -any, process -any
93 type: exitcode-stdio-1.0
93 type: exitcode-stdio-1.0
94 main-is: Main.hs
94 main-is: Main.hs
95 buildable: True
95 buildable: True
tests/Main.hs+34−14
@@ -19,41 +19,61 @@ import qualified Language.PureScript as P
19import Data.List (isSuffixOf)
19import Data.List (isSuffixOf)
20import Control.Applicative
20import Control.Applicative
21import Control.Monad
21import Control.Monad
22−import System.Exit (exitSuccess, exitFailure)
22+import System.Exit
23+import System.Process
23import System.FilePath (pathSeparator)
24import System.FilePath (pathSeparator)
24import System.Directory (getCurrentDirectory, getDirectoryContents)
25import System.Directory (getCurrentDirectory, getDirectoryContents)
26+import Text.Parsec (ParseError)
27+import qualified Paths_purescript as Paths
25import qualified System.IO.UTF8 as U
28import qualified System.IO.UTF8 as U
26import qualified Data.Map as M
29import qualified Data.Map as M
27
30
28−compile :: FilePath -> IO (Either String P.Environment)
31+preludeFilename :: IO FilePath
29−compile inputFile = do
32+preludeFilename = Paths.getDataFileName "libraries/prelude/prelude.purs"
33+
34+readInput :: [FilePath] -> IO (Either ParseError [P.Module])
35+readInput inputFiles = fmap (fmap concat . sequence) $ forM inputFiles $ \inputFile -> do
30− modules <- P.runIndentParser P.parseModules <$> U.readFile inputFile
36+ text <- U.readFile inputFile
37+ return $ P.runIndentParser P.parseModules text
38+
39+compile :: P.Options -> [FilePath] -> IO (Either String String)
40+compile opts inputFiles = do
41+ modules <- readInput inputFiles
31 case modules of
42 case modules of
32 Left parseError -> do
43 Left parseError -> do
33 return (Left $ show parseError)
44 return (Left $ show parseError)
34 Right ms -> do
45 Right ms -> do
35− case P.compile P.defaultOptions ms of
46+ case P.compile opts ms of
36 Left typeError -> do
47 Left typeError -> do
37 return (Left typeError)
48 return (Left typeError)
38− Right (_, _, env) -> do
49+ Right (js, _, _) -> do
39− return (Right env)
50+ return (Right js)
40
51
41−assert :: FilePath -> (Either String P.Environment -> Maybe String) -> IO ()
52+assert :: P.Options -> [FilePath] -> (Either String String -> IO (Maybe String)) -> IO ()
42−assert inputFile f = do
53+assert opts inputFiles f = do
43− e <- compile inputFile
54+ e <- compile opts inputFiles
55+ maybeErr <- f e
44− case f e of
56+ case maybeErr of
45− Just err -> exitFailure
57+ Just err -> putStrLn err >> exitFailure
46 Nothing -> return ()
58 Nothing -> return ()
47
59
48assertCompiles :: FilePath -> IO ()
60assertCompiles :: FilePath -> IO ()
49assertCompiles inputFile = do
61assertCompiles inputFile = do
50 putStrLn $ "assert " ++ inputFile ++ " compiles successfully"
62 putStrLn $ "assert " ++ inputFile ++ " compiles successfully"
63+ prelude <- preludeFilename
51− assert inputFile $ either Just (const Nothing)
64+ assert (P.defaultOptions { P.optionsRunMain = True }) [prelude, inputFile] $ either (return . Just) $ \js -> do
65+ (exitCode, out, err) <- readProcessWithExitCode "nodejs" [] js
66+ case exitCode of
67+ ExitSuccess -> putStrLn out >> return Nothing
68+ ExitFailure code -> return $ Just err
52
69
53assertDoesNotCompile :: FilePath -> IO ()
70assertDoesNotCompile :: FilePath -> IO ()
54assertDoesNotCompile inputFile = do
71assertDoesNotCompile inputFile = do
55 putStrLn $ "assert " ++ inputFile ++ " does not compile"
72 putStrLn $ "assert " ++ inputFile ++ " does not compile"
73+ assert P.defaultOptions [inputFile] $ \e ->
74+ case e of
75+ Left _ -> return Nothing
56− assert inputFile $ either (const Nothing) (const $ Just "Should not have compiled")
76+ Right _ -> return $ Just "Should not have compiled"
57
77
58main :: IO ()
78main :: IO ()
59main = do
79main = do