git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fixed Arrays.sort mutating the passed in list.
commit0119c5b5c81c82afe70bfa7a926dfd8b16e49883 authorjoneshf <jones3.hardy@gmail.com> dateSun 16 Feb 2014, 21:34 (13 years ago) parentd1715d8
2 files changed+12−5
examples/passing/Arrays.purs+11−4 prelude/prelude.purs+1−1
examples/passing/Arrays.purs+11−4
@@ -4,7 +4,7 @@ import Prelude
44
55test1 arr = arr !! 0 + arr !! 1 + 1
66
7−test2 = \arr -> case arr of
7+test2 = \arr -> case arr of
88 [x, y] -> x + y
99 [x] -> x
1010 [] -> 0
@@ -16,12 +16,19 @@ test3 = \tree sum -> case tree of
1616 One n -> n
1717 Some (n1 : n2 : rest) -> test3 n1 sum * 10 + test3 n2 sum * 5 + sum rest
1818
19−test4 = \arr -> case arr of
19+test4 = \arr -> case arr of
2020 [] -> 0
2121 [_] -> 0
2222 x : y : xs -> x * y + test4 xs
23−
23+
2424module Main where
2525
26−main = Trace.trace "Done"
26+import Arrays
27+import Prelude
2728
29+main = do
30+ let x = [3,2,1]
31+ let y = sort x
32+ if x == [3,2,1]
33+ then Trace.trace "Done"
34+ else Errors.throwError "Not done"
prelude/prelude.purs+1−1
@@ -578,7 +578,7 @@ module Arrays where
578578
579579 foreign import sort "function sort(l) {\
580580 \ var l1 = l.slice();\
581− \ l.sort();\
581+ \ l1.sort();\
582582 \ return l1;\
583583 \}" :: forall a. [a] -> [a]
584584