git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge branch 'master' of github.com:purescript/purescript into psci-fixes
commite46f78d54139316db36d13f3e637775c7bd71297 authorjoneshf <jones3.hardy@gmail.com> dateSun 16 Feb 2014, 22:12 (13 years ago) parent5fbc1ba2580555
4 files changed+35−6
examples/passing/Arrays.purs+11−4 prelude/prelude.purs+1−1 purescript.cabal+1−1 src/Language/PureScript/TypeChecker/Types.hs+22
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
purescript.cabal+1−1
@@ -1,5 +1,5 @@
11name: purescript
2−version: 0.4.0
2+version: 0.4.1
33cabal-version: >=1.8
44build-type: Simple
55license: MIT
src/Language/PureScript/TypeChecker/Types.hs+22
@@ -68,6 +68,7 @@ import Control.Arrow (Arrow(..))
6868
6969import qualified Data.Map as M
7070import Data.Function (on)
71+import Data.Ord (comparing)
7172
7273instance Partial Type where
7374 unknown = TUnknown
@@ -1012,6 +1013,27 @@ subsumes' (Just val) (ConstrainedType constraints ty1) ty2 = do
10121013 Just moduleName <- checkCurrentModule <$> get
10131014 _ <- subsumes' Nothing ty1 ty2
10141015 return . Just $ foldl App val (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))
1016+subsumes' val (Object r1) (Object r2) = do
1017+ let
1018+ (ts1, r1') = rowToList r1
1019+ (ts2, r2') = rowToList r2
1020+ ts1' = sortBy (comparing fst) ts1
1021+ ts2' = sortBy (comparing fst) ts2
1022+ go ts1' ts2' r1' r2'
1023+ return val
1024+ where
1025+ go [] ts2 r1 r2 = r1 =?= rowFromList (ts2, r2)
1026+ go ts1 [] r1 r2 = r2 =?= rowFromList (ts1, r1)
1027+ go ((p1, ty1) : ts1) ((p2, ty2) : ts2) r1 r2
1028+ | p1 == p2 = do subsumes Nothing ty1 ty2
1029+ go ts1 ts2 r1 r2
1030+ | p1 < p2 = do rest <- fresh
1031+ r2 =?= RCons p1 ty1 rest
1032+ go ts1 ((p2, ty2) : ts2) r1 rest
1033+ | p1 > p2 = do rest <- fresh
1034+ r1 =?= RCons p2 ty2 rest
1035+ go ((p1, ty1) : ts1) ts2 rest r2
1036+subsumes' val ty1 ty2@(Object _) = subsumes val ty2 ty1
10151037subsumes' val ty1 ty2 = do
10161038 ty1 =?= ty2
10171039 return val