git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove array type notation and cons binders
commit1f94f1250c8eede9056e7903bd1a1d8f75d2916a authorPhil Freeman <paf31@cantab.net> dateSun 26 Apr 2015, 14:43 (12 years ago) parent9db8c6c
37 files changed+137−226
examples/failing/Foldable.purs+7−5 examples/failing/OverlappingBinders.purs+3−1 examples/failing/TypeSynonyms.purs+1−1 examples/passing/ArrayType.purs+1−1 examples/passing/Arrays.purs−24 examples/passing/BindersInFunctions.purs+4−4 examples/passing/CheckSynonymBug.purs+2−2 examples/passing/DeepArrayBinder.purs+5−3 examples/passing/Do.purs+2−2 examples/passing/EmptyDataDecls.purs+2−2 examples/passing/EmptyTypeClass.purs+2−2 examples/passing/ExtendedInfixOperators.purs+4−12 examples/passing/ExternRaw.purs+2−2 examples/passing/ForeignInstance.purs+1−1 examples/passing/KindedType.purs+3−3 examples/passing/Let.purs−11 examples/passing/MultipleConstructorArgs.purs−21 examples/passing/Operators.purs+1−1 examples/passing/Patterns.purs+1−7 examples/passing/Sequence.purs+6−4 examples/passing/SequenceDesugared.purs+21−19 examples/passing/Superclasses2.purs+4−4 examples/passing/TailCall.purs+6−4 examples/passing/TopLevelCase.purs+1−1 examples/passing/TypeSynonymInData.purs+1−1 examples/passing/TypedWhere.purs+8−6 src/Language/PureScript/AST/Binders.hs−5 src/Language/PureScript/AST/Traversals.hs−6 src/Language/PureScript/CodeGen/JS.hs+1−22 src/Language/PureScript/CoreFn/Desugar.hs−3 src/Language/PureScript/Parser/Declarations.hs+3−2 src/Language/PureScript/Parser/Types.hs+7−2 src/Language/PureScript/Pretty/Types.hs−2 src/Language/PureScript/Pretty/Values.hs+1−11 src/Language/PureScript/TypeChecker/Types.hs−6 src/Language/PureScript/Types.hs−9 tests/prelude.purs+37−14
examples/failing/Foldable.purs+7−5
@@ -4,9 +4,11 @@ class Foldable f where
44 fold :: forall a b. (a -> b -> b) -> b -> f a -> b
55 size :: forall a. f a -> Number
66
7−instance foldableArray :: Foldable [] where
8− fold _ z [] = z
9− fold f z (x:xs) = x `f` (fold f z xs)
10− size = fold (const ((+) 1)) 0
7+data L a = C a (L a) | N
118
12−x = size [1,2,3]
9+instance foldableL :: Foldable L where
10+ fold _ z N = z
11+ fold f z (C x xs) = x `f` (fold f z xs)
12+ size = fold (const ((+) 1.0)) 0.0
13+
14+x = size (C 1 (C 2 (C 3 N)))
examples/failing/OverlappingBinders.purs+3−1
@@ -1,4 +1,6 @@
11module OverlappingBinders where
22
3+data S a = S a (S a)
4+
35f x = case x of
4− (y:y@(z:zs)) -> y
6+ (S y (S y@(S z zs))) -> y
examples/failing/TypeSynonyms.purs+1−1
@@ -1,5 +1,5 @@
11module Main where
22
3−type T1 = [T2]
3+type T1 = Array T2
44
55type T2 = T1
examples/passing/ArrayType.purs+1−1
@@ -3,7 +3,7 @@ module Main where
33class Pointed p where
44 point :: forall a. a -> p a
55
6−instance pointedArray :: Pointed [] where
6+instance pointedArray :: Pointed Array where
77 point a = [a]
88
99main = Debug.Trace.trace "Done"
examples/passing/Arrays.pursdeleted−24
@@ -1,24 +0,0 @@
1−module Main where
2−
3−import Prelude.Unsafe (unsafeIndex)
4−
5−test1 arr = arr `unsafeIndex` 0.0 + arr `unsafeIndex` 1.0 + 1.0
6−
7−test2 = \arr -> case arr of
8− [x, y] -> x + y
9− [x] -> x
10− [] -> 0.0
11− (x : y : _) -> x + y
12−
13−data Tree = One Number | Some [Tree]
14−
15−test3 = \tree sum -> case tree of
16− One n -> n
17− Some (n1 : n2 : rest) -> test3 n1 sum * 10.0 + test3 n2 sum * 5.0 + sum rest
18−
19−test4 = \arr -> case arr of
20− [] -> 0.0
21− [_] -> 0.0
22− x : y : xs -> x * y + test4 xs
23−
24−main = Debug.Trace.trace "Done"
examples/passing/BindersInFunctions.purs+4−4
@@ -2,7 +2,7 @@ module Main where
22
33import Prelude
44
5−tail = \(_:xs) -> xs
5+snd = \[_, y] -> y
66
77foreign import error
88 """
@@ -12,7 +12,7 @@ foreign import error
1212 """ :: forall a. String -> a
1313
1414main =
15− let ts = tail [1.0, 2.0, 3.0] in
16− if ts == [2.0, 3.0]
15+ let ts = snd [1.0, 2.0] in
16+ if ts == 2.0
1717 then Debug.Trace.trace "Done"
18− else error "Incorrect result from 'tails'."
18+ else error "Incorrect result from 'snd'."
examples/passing/CheckSynonymBug.purs+2−2
@@ -2,14 +2,14 @@ module Main where
22
33 import Prelude
44
5− type Foo a = [a]
5+ type Foo a = Array a
66
77 foreign import length
88 """
99 function length(a) {
1010 return a.length;
1111 }
12− """ :: forall a. [a] -> Number
12+ """ :: forall a. Array a -> Number
1313
1414 foo _ = length ([] :: Foo Number)
1515
examples/passing/DeepArrayBinder.purs+5−3
@@ -2,8 +2,10 @@ module Main where
22
33import Control.Monad.Eff
44
5−match2 :: [Number] -> Number
6−match2 (x : y : xs) = x * y + match2 xs
5+data List a = Cons a (List a) | Nil
6+
7+match2 :: List Number -> Number
8+match2 (Cons x (Cons y xs)) = x * y + match2 xs
79match2 _ = 0.0
810
911foreign import explode
@@ -13,6 +15,6 @@ foreign import explode
1315 }
1416 """ :: forall eff a. Eff eff a
1517
16−main = case match2 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] of
18+main = case match2 (Cons 1.0 (Cons 2.0 (Cons 3.0 (Cons 4.0 (Cons 5.0 (Cons 6.0 (Cons 7.0 (Cons 8.0 (Cons 9.0 Nil))))))))) of
1719 100.0 -> Debug.Trace.trace "Done"
1820 _ -> explode
examples/passing/Do.purs+2−2
@@ -25,8 +25,8 @@ test1 = \_ -> do
2525 Just "abc"
2626
2727test2 = \_ -> do
28− (x : _) <- Just [1.0, 2.0, 3.0]
29− (y : _) <- Just [4.0, 5.0, 6.0]
28+ x <- Just 1.0
29+ y <- Just 2.0
3030 Just (x + y)
3131
3232test3 = \_ -> do
examples/passing/EmptyDataDecls.purs+2−2
@@ -5,7 +5,7 @@ import Prelude
55data Z
66data S n
77
8−data ArrayBox n a = ArrayBox [a]
8+data ArrayBox n a = ArrayBox (Array a)
99
1010nil :: forall a. ArrayBox Z a
1111nil = ArrayBox []
@@ -17,7 +17,7 @@ foreign import concat
1717 return l1.concat(l2);
1818 };
1919 }
20− """ :: forall a. [a] -> [a] -> [a]
20+ """ :: forall a. Array a -> Array a -> Array a
2121
2222cons' :: forall a n. a -> ArrayBox n a -> ArrayBox (S n) a
2323cons' x (ArrayBox xs) = ArrayBox $ concat [x] xs
examples/passing/EmptyTypeClass.purs+2−2
@@ -4,8 +4,8 @@ import Prelude
44
55class Partial
66
7−head :: forall a. (Partial) => [a] -> a
8−head (x:xs) = x
7+head :: forall a. (Partial) => Array a -> a
8+head [x] = x
99
1010instance allowPartials :: Partial
1111
examples/passing/ExtendedInfixOperators.purs+4−12
@@ -1,20 +1,12 @@
11module Main where
22
3−zipWith :: forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
4−zipWith _ [] _ = []
5−zipWith _ _ [] = []
6−zipWith f (x:xs) (y:ys) = f x y : zipWith f xs ys
7−
8−test1 = [1.0, 2.0, 3.0] `zipWith (+)` [4.0, 5.0, 6.0]
9−
103comparing :: forall a b. (Ord b) => (a -> b) -> a -> a -> Ordering
114comparing f = compare `Data.Function.on` f
125
13−sum [] = 0.0
14−sum (x:xs) = x + sum xs
6+null [] = true
7+null _ = false
158
16−test2 = [1.0, 2.0, 3.0] `comparing sum` [4.0, 5.0, 6.0]
9+test = [1.0, 2.0, 3.0] `comparing null` [4.0, 5.0, 6.0]
1710
1811main = do
19− Debug.Trace.print test1
20− Debug.Trace.print test2
12+ Debug.Trace.print test
examples/passing/ExternRaw.purs+2−2
@@ -5,7 +5,7 @@ foreign import first
55 function first(xs) {
66 return xs[0];
77 }
8− """ :: forall a. [a] -> a
8+ """ :: forall a. Array a -> a
99
1010foreign import loop
1111 """
@@ -21,6 +21,6 @@ foreign import concat
2121 return xs.concat(ys);
2222 };
2323 }
24− """ :: forall a. [a] -> [a] -> [a]
24+ """ :: forall a. Array a -> Array a -> Array a
2525
2626main = Debug.Trace.trace "Done"
examples/passing/ForeignInstance.purs+1−1
@@ -3,7 +3,7 @@ module Main where
33class Foo a where
44 foo :: a -> String
55
6−foreign import instance fooArray :: (Foo a) => Foo [a]
6+foreign import instance fooArray :: (Foo a) => Foo (Array a)
77
88foreign import instance fooNumber :: Foo Number
99
examples/passing/KindedType.purs+3−3
@@ -4,7 +4,7 @@ type Star2Star f = f :: * -> *
44
55type Star t = t :: *
66
7−test1 :: Star2Star [] String
7+test1 :: Star2Star Array String
88test1 = ["test"]
99
1010f :: Star (String -> String)
@@ -14,12 +14,12 @@ test2 = f "test"
1414
1515data Proxy (f :: * -> *) = Proxy
1616
17−test3 :: Proxy []
17+test3 :: Proxy Array
1818test3 = Proxy
1919
2020type Test (f :: * -> *) = f String
2121
22−test4 :: Test []
22+test4 :: Test Array
2323test4 = ["test"]
2424
2525class Clazz (a :: *) where
examples/passing/Let.purs−11
@@ -26,16 +26,6 @@ test5 = let
2626 g x = f (x - 1.0) + 1.0
2727 in f 10.0
2828
29−test6 = runPure (runST (do
30− r <- newSTRef 0.0
31− (let
32− go [] = readSTRef r
33− go (n : ns) = do
34− modifySTRef r ((+) n)
35− go ns
36− in go [1.0, 2.0, 3.0, 4.0, 5.0])
37− ))
38−
3929test7 = let
4030 f :: forall a. a -> a
4131 f x = x
@@ -59,6 +49,5 @@ main = do
5949 Debug.Trace.print test3
6050 Debug.Trace.print test4
6151 Debug.Trace.print test5
62− Debug.Trace.print test6
6352 Debug.Trace.print test7
6453 Debug.Trace.print (test8 100.0)
examples/passing/MultipleConstructorArgs.pursdeleted−21
@@ -1,21 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−
6−data P a b = P a b
7−
8−runP :: forall a b r. (a -> b -> r) -> P a b -> r
9−runP f (P a b) = f a b
10−
11−idP = runP P
12−
13−testCase = \p -> case p of
14− P (x:xs) (y:ys) -> x + y
15− P _ _ -> 0.0
16−
17−test1 = testCase (P [0.0, 0.0, 0.0] [0.0, 0.0, 0.0])
18−
19−main = do
20− Debug.Trace.trace (runP (\s n -> s ++ show n) (P "Test" 0.0))
21− Debug.Trace.print test1
examples/passing/Operators.purs+1−1
@@ -46,7 +46,7 @@ module Main where
4646
4747 test10 = "Hello" `Main.bar` "World"
4848
49− (...) :: forall a. [a] -> [a] -> [a]
49+ (...) :: forall a. Array a -> Array a -> Array a
5050 (...) = \as -> \bs -> as
5151
5252 test11 = [1.0, 2.0, 0.0] ... [4.0, 5.0, 6.0]
examples/passing/Patterns.purs+1−7
@@ -11,17 +11,11 @@ module Main where
1111 { foo = "Foo" } -> o.bar
1212 _ -> 0
1313
14− g = \o -> case o of
15− { arr = [x : xs], take = "car" } -> x
16− { arr = [_, x : xs], take = "cadr" } -> x
17− _ -> 0
18−
19−
2014 h = \o -> case o of
2115 a@[_,_,_] -> a
2216 _ -> []
2317
24− isDesc :: [Number] -> Boolean
18+ isDesc :: Array Number -> Boolean
2519 isDesc [x, y] | x > y = true
2620 isDesc _ = false
2721
examples/passing/Sequence.purs+6−4
@@ -2,11 +2,13 @@ module Main where
22
33import Control.Monad.Eff
44
5+data List a = Cons a (List a) | Nil
6+
57class Sequence t where
68 sequence :: forall m a. (Monad m) => t (m a) -> m (t a)
79
8−instance sequenceArray :: Sequence [] where
9− sequence [] = pure []
10− sequence (x:xs) = (:) <$> x <*> sequence xs
10+instance sequenceList :: Sequence List where
11+ sequence Nil = pure Nil
12+ sequence (Cons x xs) = Cons <$> x <*> sequence xs
1113
12−main = sequence $ [Debug.Trace.trace "Done"]
14+main = sequence $ Cons (Debug.Trace.trace "Done") Nil
examples/passing/SequenceDesugared.purs+21−19
@@ -2,33 +2,35 @@ module Main where
22
33import Control.Monad.Eff
44
5+data List a = Cons a (List a) | Nil
6+
57data Sequence t = Sequence (forall m a. (Monad m) => t (m a) -> m (t a))
68
79sequence :: forall t. Sequence t -> (forall m a. (Monad m) => t (m a) -> m (t a))
810sequence (Sequence s) = s
911
10−sequenceArraySeq :: forall m a. (Monad m) => Array (m a) -> m (Array a)
11−sequenceArraySeq [] = pure []
12−sequenceArraySeq (x:xs) = (:) <$> x <*> sequenceArraySeq xs
12+sequenceListSeq :: forall m a. (Monad m) => List (m a) -> m (List a)
13+sequenceListSeq Nil = pure Nil
14+sequenceListSeq (Cons x xs) = Cons <$> x <*> sequenceListSeq xs
1315
14−sequenceArray :: Sequence []
15−sequenceArray = Sequence (sequenceArraySeq)
16+sequenceList :: Sequence List
17+sequenceList = Sequence (sequenceListSeq)
1618
17−sequenceArray' :: Sequence []
18−sequenceArray' = Sequence ((\val -> case val of
19− [] -> pure []
20− (x:xs) -> (:) <$> x <*> sequence sequenceArray' xs))
19+sequenceList' :: Sequence List
20+sequenceList' = Sequence ((\val -> case val of
21+ Nil -> pure Nil
22+ Cons x xs -> Cons <$> x <*> sequence sequenceList' xs))
2123
22−sequenceArray'' :: Sequence []
23−sequenceArray'' = Sequence (sequenceArraySeq :: forall m a. (Monad m) => Array (m a) -> m (Array a))
24+sequenceList'' :: Sequence List
25+sequenceList'' = Sequence (sequenceListSeq :: forall m a. (Monad m) => List (m a) -> m (List a))
2426
25−sequenceArray''' :: Sequence []
26−sequenceArray''' = Sequence ((\val -> case val of
27− [] -> pure []
28− (x:xs) -> (:) <$> x <*> sequence sequenceArray''' xs) :: forall m a. (Monad m) => Array (m a) -> m (Array a))
27+sequenceList''' :: Sequence List
28+sequenceList''' = Sequence ((\val -> case val of
29+ Nil -> pure Nil
30+ Cons x xs -> Cons <$> x <*> sequence sequenceList''' xs) :: forall m a. (Monad m) => List (m a) -> m (List a))
2931
3032main = do
31− sequence sequenceArray $ [Debug.Trace.trace "Done"]
32− sequence sequenceArray' $ [Debug.Trace.trace "Done"]
33− sequence sequenceArray'' $ [Debug.Trace.trace "Done"]
34− sequence sequenceArray''' $ [Debug.Trace.trace "Done"]
33+ sequence sequenceList $ Cons (Debug.Trace.trace "Done") Nil
34+ sequence sequenceList' $ Cons (Debug.Trace.trace "Done") Nil
35+ sequence sequenceList'' $ Cons (Debug.Trace.trace "Done") Nil
36+ sequence sequenceList''' $ Cons (Debug.Trace.trace "Done") Nil
examples/passing/Superclasses2.purs+4−4
@@ -5,19 +5,19 @@ import Prelude.Unsafe (unsafeIndex)
55class Su a where
66 su :: a -> a
77
8−class (Su [a]) <= Cl a where
8+class (Su (Array a)) <= Cl a where
99 cl :: a -> a -> a
1010
1111instance suNumber :: Su Number where
1212 su n = n + 1.0
1313
14−instance suArray :: (Su a) => Su [a] where
15− su (x : _) = [su x]
14+instance suArray :: (Su a) => Su (Array a) where
15+ su [x] = [su x]
1616
1717instance clNumber :: Cl Number where
1818 cl n m = n + m
1919
20−test :: forall a. (Cl a) => a -> [a]
20+test :: forall a. (Cl a) => a -> Array a
2121test x = su [cl x x]
2222
2323main = Debug.Trace.print $ test 10.0 `unsafeIndex` 0.0
examples/passing/TailCall.purs+6−4
@@ -2,9 +2,11 @@ module Main where
22
33import Prelude
44
5−test :: Number -> [Number] -> Number
6−test n [] = n
7−test n (x:xs) = test (n + x) xs
5+data L a = C a (L a) | N
6+
7+test :: Number -> L Number -> Number
8+test n N = n
9+test n (C x xs) = test (n + x) xs
810
911loop :: forall a. Number -> a
1012loop x = loop (x + 1.0)
@@ -12,4 +14,4 @@ loop x = loop (x + 1.0)
1214notATailCall = \x ->
1315 (\notATailCall -> notATailCall x) (\x -> x)
1416
15−main = Debug.Trace.print (test 0.0 [1.0, 2.0, 3.0])
17+main = Debug.Trace.print (test 0.0 (1.0 `C` (2.0 `C` (3.0 `C` N))))
examples/passing/TopLevelCase.purs+1−1
@@ -18,7 +18,7 @@ gcd x 0.0 = x
1818gcd x y | x > y = gcd (x % y) y
1919gcd x y = gcd (y % x) x
2020
21−guardsTest (x:xs) | x > 0.0 = guardsTest xs
21+guardsTest [x] | x > 0.0 = []
2222guardsTest xs = xs
2323
2424data A = A
examples/passing/TypeSynonymInData.purs+1−1
@@ -1,6 +1,6 @@
11module Main where
22
3−type A a = [a]
3+type A a = Array a
44
55data Foo a = Foo (A a) | Bar
66
examples/passing/TypedWhere.purs+8−6
@@ -2,12 +2,14 @@ module Main where
22
33data E a b = L a | R b
44
5−lefts :: forall a b. [E a b] -> [a]
6−lefts = go []
5+data L a = C a (L a) | N
6+
7+lefts :: forall a b. L (E a b) -> L a
8+lefts = go N
79 where
8− go :: forall a b. [a] -> [E a b] -> [a]
9− go ls [] = ls
10− go ls (L a : rest) = go (a : ls) rest
11− go ls (_ : rest) = go ls rest
10+ go :: forall a b. L a -> L (E a b) -> L a
11+ go ls N = ls
12+ go ls (C (L a) rest) = go (C a ls) rest
13+ go ls (C _ rest) = go ls rest
1214
1315main = Debug.Trace.trace "Done"
src/Language/PureScript/AST/Binders.hs−5
@@ -63,10 +63,6 @@ data Binder
6363 --
6464 | ArrayBinder [Binder]
6565 -- |
66− -- A binder which matches an array and binds its head and tail
67− --
68− | ConsBinder Binder Binder
69− -- |
7066 -- A binder which binds its input to an identifier
7167 --
7268 | NamedBinder Ident Binder
@@ -85,7 +81,6 @@ binderNames = go []
8581 go ns (ConstructorBinder _ bs) = foldl go ns bs
8682 go ns (ObjectBinder bs) = foldl go ns (map snd bs)
8783 go ns (ArrayBinder bs) = foldl go ns bs
88− go ns (ConsBinder b1 b2) = go (go ns b1) b2
8984 go ns (NamedBinder name b) = go (name : ns) b
9085 go ns (PositionedBinder _ _ b) = go ns b
9186 go ns _ = ns
src/Language/PureScript/AST/Traversals.hs−6
@@ -68,7 +68,6 @@ everywhereOnValues f g h = (f', g', h')
6868 h' (ConstructorBinder ctor bs) = h (ConstructorBinder ctor (map h' bs))
6969 h' (ObjectBinder bs) = h (ObjectBinder (map (fmap h') bs))
7070 h' (ArrayBinder bs) = h (ArrayBinder (map h' bs))
71− h' (ConsBinder b1 b2) = h (ConsBinder (h' b1) (h' b2))
7271 h' (NamedBinder name b) = h (NamedBinder name (h' b))
7372 h' (PositionedBinder pos com b) = h (PositionedBinder pos com (h' b))
7473 h' other = h other
@@ -125,7 +124,6 @@ everywhereOnValuesTopDownM f g h = (f' <=< f, g' <=< g, h' <=< h)
125124 h' (ConstructorBinder ctor bs) = ConstructorBinder ctor <$> mapM (h' <=< h) bs
126125 h' (ObjectBinder bs) = ObjectBinder <$> mapM (sndM (h' <=< h)) bs
127126 h' (ArrayBinder bs) = ArrayBinder <$> mapM (h' <=< h) bs
128− h' (ConsBinder b1 b2) = ConsBinder <$> (h b1 >>= h') <*> (h b2 >>= h')
129127 h' (NamedBinder name b) = NamedBinder name <$> (h b >>= h')
130128 h' (PositionedBinder pos com b) = PositionedBinder pos com <$> (h b >>= h')
131129 h' other = h other
@@ -178,7 +176,6 @@ everywhereOnValuesM f g h = (f', g', h')
178176 h' (ConstructorBinder ctor bs) = (ConstructorBinder ctor <$> mapM h' bs) >>= h
179177 h' (ObjectBinder bs) = (ObjectBinder <$> mapM (sndM h') bs) >>= h
180178 h' (ArrayBinder bs) = (ArrayBinder <$> mapM h' bs) >>= h
181− h' (ConsBinder b1 b2) = (ConsBinder <$> h' b1 <*> h' b2) >>= h
182179 h' (NamedBinder name b) = (NamedBinder name <$> h' b) >>= h
183180 h' (PositionedBinder pos com b) = (PositionedBinder pos com <$> h' b) >>= h
184181 h' other = h other
@@ -234,7 +231,6 @@ everythingOnValues (<>) f g h i j = (f', g', h', i', j')
234231 h' b@(ConstructorBinder _ bs) = foldl (<>) (h b) (map h' bs)
235232 h' b@(ObjectBinder bs) = foldl (<>) (h b) (map (h' . snd) bs)
236233 h' b@(ArrayBinder bs) = foldl (<>) (h b) (map h' bs)
237− h' b@(ConsBinder b1 b2) = h b <> h' b1 <> h' b2
238234 h' b@(NamedBinder _ b1) = h b <> h' b1
239235 h' b@(PositionedBinder _ _ b1) = h b <> h' b1
240236 h' b = h b
@@ -303,7 +299,6 @@ everythingWithContextOnValues s0 r0 (<>) f g h i j = (f'' s0, g'' s0, h'' s0, i'
303299 h' s (ConstructorBinder _ bs) = foldl (<>) r0 (map (h'' s) bs)
304300 h' s (ObjectBinder bs) = foldl (<>) r0 (map (h'' s . snd) bs)
305301 h' s (ArrayBinder bs) = foldl (<>) r0 (map (h'' s) bs)
306− h' s (ConsBinder b1 b2) = h'' s b1 <> h'' s b2
307302 h' s (NamedBinder _ b1) = h'' s b1
308303 h' s (PositionedBinder _ _ b1) = h'' s b1
309304 h' _ _ = r0
@@ -373,7 +368,6 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
373368 h' s (ConstructorBinder ctor bs) = ConstructorBinder ctor <$> mapM (h'' s) bs
374369 h' s (ObjectBinder bs) = ObjectBinder <$> mapM (sndM (h'' s)) bs
375370 h' s (ArrayBinder bs) = ArrayBinder <$> mapM (h'' s) bs
376− h' s (ConsBinder b1 b2) = ConsBinder <$> h'' s b1 <*> h'' s b2
377371 h' s (NamedBinder name b) = NamedBinder name <$> h'' s b
378372 h' s (PositionedBinder pos com b) = PositionedBinder pos com <$> h'' s b
379373 h' _ other = return other
src/Language/PureScript/CodeGen/JS.hs+1−22
@@ -30,7 +30,7 @@ import qualified Data.Traversable as T (traverse)
3030
3131import Control.Applicative
3232import Control.Arrow ((&&&))
33−import Control.Monad (foldM, replicateM, forM)
33+import Control.Monad (replicateM, forM)
3434import Control.Monad.Reader (MonadReader, asks)
3535import Control.Monad.Supply.Class
3636
@@ -315,23 +315,6 @@ moduleToJs (Module coms mn imps exps foreigns decls) = do
315315 done'' <- go remain done'
316316 js <- binderToJs argVar done'' binder
317317 return (JSVariableIntroduction argVar (Just (JSAccessor (identToJs field) (JSVar varName))) : js)
318− binderToJs varName done binder@(ConstructorBinder _ _ ctor _) | isCons ctor = do
319− let (headBinders, tailBinder) = uncons [] binder
320− numberOfHeadBinders = fromIntegral $ length headBinders
321− js1 <- foldM (\done' (headBinder, index) -> do
322− headVar <- freshName
323− jss <- binderToJs headVar done' headBinder
324− return (JSVariableIntroduction headVar (Just (JSIndexer (JSNumericLiteral (Left index)) (JSVar varName))) : jss)) done (zip headBinders [0..])
325− tailVar <- freshName
326− js2 <- binderToJs tailVar js1 tailBinder
327− return [JSIfElse (JSBinary GreaterThanOrEqualTo (JSAccessor "length" (JSVar varName)) (JSNumericLiteral (Left numberOfHeadBinders))) (JSBlock
328− ( JSVariableIntroduction tailVar (Just (JSApp (JSAccessor "slice" (JSVar varName)) [JSNumericLiteral (Left numberOfHeadBinders)])) :
329− js2
330− )) Nothing]
331− where
332− uncons :: [Binder Ann] -> Binder Ann -> ([Binder Ann], Binder Ann)
333− uncons acc (ConstructorBinder _ _ ctor' [h, t]) | isCons ctor' = uncons (h : acc) t
334− uncons acc tailBinder = (reverse acc, tailBinder)
335318 binderToJs _ _ b@(ConstructorBinder{}) =
336319 error $ "Invalid ConstructorBinder in binderToJs: " ++ show b
337320 binderToJs varName done (NamedBinder _ ident binder) = do
@@ -369,7 +352,3 @@ moduleToJs (Module coms mn imps exps foreigns decls) = do
369352 done'' <- go done' (index + 1) bs'
370353 js <- binderToJs elVar done'' binder
371354 return (JSVariableIntroduction elVar (Just (JSIndexer (JSNumericLiteral (Left index)) (JSVar varName))) : js)
372−
373− isCons :: Qualified ProperName -> Bool
374− isCons (Qualified (Just mn') ctor) = mn' == ModuleName [ProperName C.prim] && ctor == ProperName "Array"
375− isCons name = error $ "Unexpected argument in isCons: " ++ show name
src/Language/PureScript/CoreFn/Desugar.hs−3
@@ -162,9 +162,6 @@ moduleToCoreFn env (A.Module coms mn decls (Just exps)) =
162162 LiteralBinder (ss, com, Nothing, Nothing) (ObjectLiteral $ map (second (binderToCoreFn ss [])) bs)
163163 binderToCoreFn ss com (A.ArrayBinder bs) =
164164 LiteralBinder (ss, com, Nothing, Nothing) (ArrayLiteral $ map (binderToCoreFn ss []) bs)
165− binderToCoreFn ss com (A.ConsBinder b1 b2) =
166− let arrCtor = Qualified (Just $ ModuleName [ProperName "Prim"]) (ProperName "Array")
167− in ConstructorBinder (ss, com, Nothing, Nothing) arrCtor arrCtor $ map (binderToCoreFn ss []) [b1, b2]
168165 binderToCoreFn ss com (A.NamedBinder name b) =
169166 NamedBinder (ss, com, Nothing, Nothing) name (binderToCoreFn ss [] b)
170167 binderToCoreFn _ com (A.PositionedBinder ss com1 b) =
src/Language/PureScript/Parser/Declarations.hs+3−2
@@ -493,9 +493,10 @@ parseIdentifierAndBinder = do
493493-- Parse a binder
494494--
495495parseBinder :: TokenParser Binder
496−parseBinder = withSourceSpan PositionedBinder (P.buildExpressionParser operators parseBinderAtom P.<?> "expression")
496+parseBinder = withSourceSpan PositionedBinder (P.buildExpressionParser operators parseBinderAtom)
497497 where
498− operators = [ [ P.Infix (P.try $ C.indented *> colon *> return ConsBinder) P.AssocRight ] ]
498+ -- TODO: remove this deprecation warning in 0.8
499+ operators = [ [ P.Infix (P.try $ C.indented *> colon *> return (error "Cons binders are no longer supported. Consider using purescript-lists or purescript-sequences instead.")) P.AssocRight ] ]
499500 parseBinderAtom :: TokenParser Binder
500501 parseBinderAtom = P.choice (map P.try
501502 [ parseNullBinder
src/Language/PureScript/Parser/Types.hs+7−2
@@ -32,11 +32,16 @@ import Language.PureScript.Environment
3232import qualified Text.Parsec as P
3333import qualified Text.Parsec.Expr as P
3434
35+-- TODO: remove these deprecation warnings in 0.8
3536parseArray :: TokenParser Type
36−parseArray = squares $ return tyArray
37+parseArray = do
38+ _ <- squares $ return tyArray
39+ return $ error "Array notation is no longer supported. Use Array instead of []."
3740
3841parseArrayOf :: TokenParser Type
39−parseArrayOf = squares $ TypeApp tyArray <$> parseType
42+parseArrayOf = do
43+ _ <- squares $ TypeApp tyArray <$> parseType
44+ return $ error "Array notation is no longer supported. Use Array _ instead of [_]."
4045
4146parseFunction :: TokenParser Type
4247parseFunction = parens $ rarrow >> return tyFunction
src/Language/PureScript/Pretty/Types.hs−2
@@ -37,7 +37,6 @@ typeLiterals = mkPattern match
3737 match TypeWildcard = Just "_"
3838 match (TypeVar var) = Just var
3939 match (PrettyPrintObject row) = Just $ "{ " ++ prettyPrintRow row ++ " }"
40− match (PrettyPrintArray ty) = Just $ "[" ++ prettyPrintType ty ++ "]"
4140 match (TypeConstructor ctor) = Just $ show ctor
4241 match (TUnknown u) = Just $ 'u' : show u
4342 match (Skolem name s _) = Just $ name ++ show s
@@ -84,7 +83,6 @@ insertPlaceholders :: Type -> Type
8483insertPlaceholders = everywhereOnTypesTopDown convertForAlls . everywhereOnTypes convert
8584 where
8685 convert (TypeApp (TypeApp f arg) ret) | f == tyFunction = PrettyPrintFunction arg ret
87− convert (TypeApp a el) | a == tyArray = PrettyPrintArray el
8886 convert (TypeApp o r) | o == tyObject = PrettyPrintObject r
8987 convert other = other
9088 convertForAlls (ForAll ident ty _) = go [ident] ty
src/Language/PureScript/Pretty/Values.hs+1−11
@@ -216,7 +216,6 @@ prettyPrintBinderAtom = mkPattern' match
216216 ]
217217 match (NamedBinder ident binder) = ((show ident ++ "@") ++) <$> prettyPrintBinder' binder
218218 match (PositionedBinder _ _ binder) = prettyPrintBinder' binder
219− match _ = mzero
220219
221220-- |
222221-- Generate a pretty-printed string representing a Binder
@@ -228,16 +227,7 @@ prettyPrintBinder' :: Binder -> StateT PrinterState Maybe String
228227prettyPrintBinder' = runKleisli $ runPattern matchBinder
229228 where
230229 matchBinder :: Pattern PrinterState Binder String
231− matchBinder = buildPrettyPrinter operators (prettyPrintBinderAtom <+> fmap parens matchBinder)
232− operators :: OperatorTable PrinterState Binder String
233− operators =
234− OperatorTable [ [ AssocR matchConsBinder (\b1 b2 -> b1 ++ " : " ++ b2) ] ]
235−
236−matchConsBinder :: Pattern PrinterState Binder (Binder, Binder)
237−matchConsBinder = mkPattern match'
238− where
239− match' (ConsBinder b1 b2) = Just (b1, b2)
240− match' _ = Nothing
230+ matchBinder = prettyPrintBinderAtom <+> fmap parens matchBinder
241231
242232prettyPrintObjectPropertyBinder :: (String, Binder) -> StateT PrinterState Maybe String
243233prettyPrintObjectPropertyBinder (key, binder) = concat <$> sequence
src/Language/PureScript/TypeChecker/Types.hs−6
@@ -391,12 +391,6 @@ inferBinder val (ArrayBinder binders) = do
391391 m1 <- M.unions <$> mapM (inferBinder el) binders
392392 val =?= TypeApp tyArray el
393393 return m1
394−inferBinder val (ConsBinder headBinder tailBinder) = do
395− el <- fresh
396− m1 <- inferBinder el headBinder
397− m2 <- inferBinder val tailBinder
398− val =?= TypeApp tyArray el
399− return $ m1 `M.union` m2
400394inferBinder val (NamedBinder name binder) = do
401395 m <- inferBinder val binder
402396 return $ M.insert name val m
src/Language/PureScript/Types.hs−9
@@ -94,10 +94,6 @@ data Type
9494 -- |
9595 -- A placeholder used in pretty printing
9696 --
97− | PrettyPrintArray Type
98− -- |
99− -- A placeholder used in pretty printing
100− --
10197 | PrettyPrintObject Type
10298 -- |
10399 -- A placeholder used in pretty printing
@@ -248,7 +244,6 @@ everywhereOnTypes f = go
248244 go (RCons name ty rest) = f (RCons name (go ty) (go rest))
249245 go (KindedType ty k) = f (KindedType (go ty) k)
250246 go (PrettyPrintFunction t1 t2) = f (PrettyPrintFunction (go t1) (go t2))
251− go (PrettyPrintArray t) = f (PrettyPrintArray (go t))
252247 go (PrettyPrintObject t) = f (PrettyPrintObject (go t))
253248 go (PrettyPrintForAll args t) = f (PrettyPrintForAll args (go t))
254249 go other = f other
@@ -263,7 +258,6 @@ everywhereOnTypesTopDown f = go . f
263258 go (RCons name ty rest) = RCons name (go (f ty)) (go (f rest))
264259 go (KindedType ty k) = KindedType (go (f ty)) k
265260 go (PrettyPrintFunction t1 t2) = PrettyPrintFunction (go (f t1)) (go (f t2))
266− go (PrettyPrintArray t) = PrettyPrintArray (go (f t))
267261 go (PrettyPrintObject t) = PrettyPrintObject (go (f t))
268262 go (PrettyPrintForAll args t) = PrettyPrintForAll args (go (f t))
269263 go other = f other
@@ -278,7 +272,6 @@ everywhereOnTypesM f = go
278272 go (RCons name ty rest) = (RCons name <$> go ty <*> go rest) >>= f
279273 go (KindedType ty k) = (KindedType <$> go ty <*> pure k) >>= f
280274 go (PrettyPrintFunction t1 t2) = (PrettyPrintFunction <$> go t1 <*> go t2) >>= f
281− go (PrettyPrintArray t) = (PrettyPrintArray <$> go t) >>= f
282275 go (PrettyPrintObject t) = (PrettyPrintObject <$> go t) >>= f
283276 go (PrettyPrintForAll args t) = (PrettyPrintForAll args <$> go t) >>= f
284277 go other = f other
@@ -293,7 +286,6 @@ everywhereOnTypesTopDownM f = go <=< f
293286 go (RCons name ty rest) = RCons name <$> (f ty >>= go) <*> (f rest >>= go)
294287 go (KindedType ty k) = KindedType <$> (f ty >>= go) <*> pure k
295288 go (PrettyPrintFunction t1 t2) = PrettyPrintFunction <$> (f t1 >>= go) <*> (f t2 >>= go)
296− go (PrettyPrintArray t) = PrettyPrintArray <$> (f t >>= go)
297289 go (PrettyPrintObject t) = PrettyPrintObject <$> (f t >>= go)
298290 go (PrettyPrintForAll args t) = PrettyPrintForAll args <$> (f t >>= go)
299291 go other = f other
@@ -308,7 +300,6 @@ everythingOnTypes (<>) f = go
308300 go t@(RCons _ ty rest) = f t <> go ty <> go rest
309301 go t@(KindedType ty _) = f t <> go ty
310302 go t@(PrettyPrintFunction t1 t2) = f t <> go t1 <> go t2
311− go t@(PrettyPrintArray t1) = f t <> go t1
312303 go t@(PrettyPrintObject t1) = f t <> go t1
313304 go t@(PrettyPrintForAll _ t1) = f t <> go t1
314305 go other = f other
tests/prelude.purs+37−14
@@ -68,11 +68,11 @@ module Prelude
6868 return [e].concat(l);
6969 };
7070 }
71− """ :: forall a. a -> [a] -> [a]
71+ """ :: forall a. a -> Array a -> Array a
7272
7373 infixr 6 :
7474
75− (:) :: forall a. a -> [a] -> [a]
75+ (:) :: forall a. a -> Array a -> Array a
7676 (:) = cons
7777
7878 infixr 9 >>>
@@ -303,7 +303,7 @@ module Prelude
303303 (==) _ _ = true
304304 (/=) _ _ = false
305305
306− instance eqArray :: (Eq a) => Eq [a] where
306+ instance eqArray :: (Eq a) => Eq (Array a) where
307307 (==) = eqArrayImpl (==)
308308 (/=) xs ys = not (xs == ys)
309309
@@ -345,7 +345,7 @@ module Prelude
345345 };
346346 };
347347 }
348− """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
348+ """ :: forall a. (a -> a -> Boolean) -> Array a -> Array a -> Boolean
349349
350350 data Ordering = LT | GT | EQ
351351
@@ -367,13 +367,36 @@ module Prelude
367367 instance ordUnit :: Ord Unit where
368368 compare _ _ = EQ
369369
370− instance ordArray :: (Ord a) => Ord [a] where
371− compare [] [] = EQ
372− compare [] _ = LT
373− compare _ [] = GT
374− compare (x:xs) (y:ys) = case compare x y of
375− EQ -> compare xs ys
376− other -> other
370+ instance ordArray :: (Ord a) => Ord (Array a) where
371+ compare xs ys = compare 0.0 $ ordArrayImpl (\x y -> case compare x y of
372+ EQ -> 0.0
373+ LT -> -1.0
374+ GT -> 1.0) xs ys
375+
376+ foreign import ordArrayImpl """
377+ function ordArrayImpl(f) {
378+ return function (ys) {
379+ return function (ys) {
380+ var i = 0;
381+ while (i < xs.length && i < ys.length) {
382+ var x = xs[i];
383+ var y = ys[i];
384+ var o = f(x)(y);
385+ if (o !== 0) {
386+ return o;
387+ }
388+ }
389+ if (xs.length == ys.length) {
390+ return 0;
391+ } else if (xs.length > ys.length) {
392+ return 1;
393+ } else {
394+ return -1;
395+ }
396+ };
397+ };
398+ }
399+ """ :: forall a. (a -> a -> Number) -> Array a -> Array a -> Number
377400
378401 instance ordOrdering :: Ord Ordering where
379402 compare LT LT = EQ
@@ -532,7 +555,7 @@ module Prelude
532555 instance showUnit :: Show Unit where
533556 show _ = "unit"
534557
535− instance showArray :: (Show a) => Show [a] where
558+ instance showArray :: (Show a) => Show (Array a) where
536559 show = showArrayImpl show
537560
538561 instance showOrdering :: Show Ordering where
@@ -565,7 +588,7 @@ module Prelude
565588 return '[' + ss.join(',') + ']';
566589 };
567590 }
568− """ :: forall a. (a -> String) -> [a] -> String
591+ """ :: forall a. (a -> String) -> Array a -> String
569592
570593module Data.Function where
571594
@@ -889,7 +912,7 @@ module Prelude.Unsafe where
889912 return xs[n];
890913 };
891914 }
892− """ :: forall a. [a] -> Number -> a
915+ """ :: forall a. Array a -> Number -> a
893916
894917module Control.Monad.Eff
895918 ( Eff()