on master help sign in
Merge branch 'master' into canonicalize
9253595Evan Czaplicki
.gitignore+2
@@ -1,5 +1,7 @@
1dist
1dist
2cabal-dev
2cabal-dev
3+.cabal-sandbox/
4+cabal.sandbox.config
3*.o
5*.o
4*.hi
6*.hi
5*.chi
7*.chi
changelog.md+7−1
@@ -1,7 +1,13 @@
1
1
2+## 0.12.3
3+
4+ * Minor changes to support webgl as a separate library
5+ * Switch from HSV to HSL
6+ * Programmatic access to colors with toHsl and toRgb
7+
2## 0.12.1
8## 0.12.1
3
9
4−## Improvements:
10+#### Improvements:
5
11
6 * New Array library (thanks entirely to @Xashili)
12 * New Array library (thanks entirely to @Xashili)
7 * Json.Value can flow through ports
13 * Json.Value can flow through ports
compiler/Metadata/Prelude.hs+1−1
@@ -42,7 +42,7 @@ safeReadDocs name =
42 hPutStrLn stderr $ unlines $
42 hPutStrLn stderr $ unlines $
43 [ "Error reading types for standard library from file " ++ name
43 [ "Error reading types for standard library from file " ++ name
44 , " If you are using a stable version of Elm, please report an issue at"
44 , " If you are using a stable version of Elm, please report an issue at"
45− , " <http://github.com/evancz/Elm/issues> specifying version numbers for"
45+ , " <http://github.com/elm-lang/Elm/issues> specifying version numbers for"
46 , " Elm and your OS." ]
46 , " Elm and your OS." ]
47 exitFailure
47 exitFailure
48
48
libraries/Debug.elm+29−2
@@ -2,10 +2,11 @@ module Debug where
2{-| This library is for investigating bugs or performance problems. It should
2{-| This library is for investigating bugs or performance problems. It should
3*not* be used in production code.
3*not* be used in production code.
4
4
5−@docs log
5+@docs log, crash
6-}
6-}
7
7
8import Native.Debug
8import Native.Debug
9+import Native.Error
9
10
10{-| Log a tagged value on the developer console, and then return the value.
11{-| Log a tagged value on the developer console, and then return the value.
11
12
@@ -16,4 +17,30 @@ Notice that `log` is not a pure function! It should *only* be used for
16investigating bugs or performance problems.
17investigating bugs or performance problems.
17-}
18-}
18log : String -> a -> a
19log : String -> a -> a
19−log = Native.Debug.log
20+log = Native.Debug.log
21+
22+{-| Crash the program with an error message. This is an uncatchable error,
23+intended for code that is soon-to-be-implemented. For example, if you are
24+working with a large ADT and have partially completed a case expression, it may
25+make sense to do this:
26+
27+ data Entity = Ship | Fish | Captain | Seagull
28+
29+ drawEntity entity =
30+ case entity of
31+ Ship -> ...
32+ Fish -> ...
33+ _ -> Debug.crash ("drawEntity not implemented for " ++ show entity ++ " yet!")
34+
35+Note that incomplete pattern matches are *very* bad practice! They are one of
36+the very few ways to crash an Elm program, and they are completely avoidable.
37+Production code should not have incomplete pattern matches!
38+
39+**Use this if** you want to do some testing while you are partway through
40+writing a function.
41+
42+**Do not use this if** you want to do some typical try-catch exception handling.
43+Use the `Maybe` or `Either` libraries instead.
44+-}
45+crash : String -> a
46+crash = Native.Error.raise
libraries/Dict.elm+1−1
@@ -249,7 +249,7 @@ reportRemBug msg c lgot rgot =
249 lgot,
249 lgot,
250 " ",
250 " ",
251 rgot,
251 rgot,
252− "\nPlease report this bug to https://github.com/evancz/Elm/issues"
252+ "\nPlease report this bug to https://github.com/elm-lang/Elm/issues"
253 ]
253 ]
254
254
255-- Remove the top node from the tree, may leave behind BBlacks
255-- Remove the top node from the tree, may leave behind BBlacks
libraries/Native/Array.js+21−7
@@ -255,15 +255,27 @@ Elm.Native.Array.make = function(elm) {
255 }
255 }
256
256
257 function foldl(f, b, a) {
257 function foldl(f, b, a) {
258− for (var i = 0; i < a.table.length; i++) {
258+ if (a.height == 0) {
259+ for (var i = 0; i < a.table.length; i++) {
260+ b = A2(f, a.table[i], b);
261+ }
262+ } else {
263+ for (var i = 0; i < a.table.length; i++) {
259− b = A2(f, a.height == 0 ? a.table[i] : foldl(f, b, a.table[i]), b);
264+ b = foldl(f, b, a.table[i]);
265+ }
260 }
266 }
261 return b;
267 return b;
262 }
268 }
263
269
264 function foldr(f, b, a) {
270 function foldr(f, b, a) {
265− for (var i = a.table.length; i--; ) {
271+ if (a.height == 0) {
266− b = A2(f, a.height == 0 ? a.table[i] : foldr(f, b, a.table[i]), b);
272+ for (var i = a.table.length; i--; ) {
273+ b = A2(f, a.table[i], b);
274+ }
275+ } else {
276+ for (var i = a.table.length; i--; ) {
277+ b = foldl(f, b, a.table[i]);
278+ }
267 }
279 }
268 return b;
280 return b;
269 }
281 }
@@ -345,9 +357,11 @@ Elm.Native.Array.make = function(elm) {
345 // TODO: Add support for appending trees of different sizes. Current
357 // TODO: Add support for appending trees of different sizes. Current
346 // behavior will just rise the lower tree and then append them.
358 // behavior will just rise the lower tree and then append them.
347 function append(a,b) {
359 function append(a,b) {
360+ if (a.table.length == 0) return b;
361+ if (b.table.length == 0) return a;
348− if (b.height > a.height) { return append(parentise(a, b.height), b); }
362+ if (b.height > a.height) return append(parentise(a, b.height), b);
349− if (a.height > b.height) { return append(a, parentise(b, a.height)); }
363+ if (a.height > b.height) return append(a, parentise(b, a.height));
350− if (a.height == 0) { return append(parentise(a, 1), parentise(b, 1)); }
364+ if (a.height == 0) return append(parentise(a, 1), parentise(b, 1));
351
365
352 var c = append_(a, b);
366 var c = append_(a, b);
353 if (c[1].table.length > 0) {
367 if (c[1].table.length > 0) {
libraries/Native/Char.js+6−4
@@ -4,6 +4,8 @@ Elm.Native.Char.make = function(elm) {
4 elm.Native.Char = elm.Native.Char || {};
4 elm.Native.Char = elm.Native.Char || {};
5 if (elm.Native.Char.values) return elm.Native.Char.values;
5 if (elm.Native.Char.values) return elm.Native.Char.values;
6
6
7+ var Utils = Elm.Native.Utils.make(elm);
8+
7 function isBetween(lo,hi) { return function(chr) {
9 function isBetween(lo,hi) { return function(chr) {
8 var c = chr.charCodeAt(0);
10 var c = chr.charCodeAt(0);
9 return lo <= c && c <= hi;
11 return lo <= c && c <= hi;
@@ -16,10 +18,10 @@ Elm.Native.Char.make = function(elm) {
16 return elm.Native.Char.values = {
18 return elm.Native.Char.values = {
17 fromCode : function(c) { return String.fromCharCode(c); },
19 fromCode : function(c) { return String.fromCharCode(c); },
18 toCode : function(c) { return c.toUpperCase().charCodeAt(0); },
20 toCode : function(c) { return c.toUpperCase().charCodeAt(0); },
19− toUpper : function(c) { return c.toUpperCase(); },
21+ toUpper : function(c) { return Utils.chr(c.toUpperCase()); },
20− toLower : function(c) { return c.toLowerCase(); },
22+ toLower : function(c) { return Utils.chr(c.toLowerCase()); },
21− toLocaleUpper : function(c) { return c.toLocaleUpperCase(); },
23+ toLocaleUpper : function(c) { return Utils.chr(c.toLocaleUpperCase()); },
22− toLocaleLower : function(c) { return c.toLocaleLowerCase(); },
24+ toLocaleLower : function(c) { return Utils.chr(c.toLocaleLowerCase()); },
23 isLower : isBetween('a'.charCodeAt(0),'z'.charCodeAt(0)),
25 isLower : isBetween('a'.charCodeAt(0),'z'.charCodeAt(0)),
24 isUpper : isBetween('A'.charCodeAt(0),'Z'.charCodeAt(0)),
26 isUpper : isBetween('A'.charCodeAt(0),'Z'.charCodeAt(0)),
25 isDigit : isDigit,
27 isDigit : isDigit,
libraries/Native/Signal/WebSocket.js+1−1
@@ -9,7 +9,7 @@ Elm.Native.WebSocket.make = function(elm) {
9 var List = Elm.Native.List.make(elm);
9 var List = Elm.Native.List.make(elm);
10
10
11 function open(url, outgoing) {
11 function open(url, outgoing) {
12− var incoming = Signal.constant(List.Nil);
12+ var incoming = Signal.constant("");
13 var ws = new WebSocket(url);
13 var ws = new WebSocket(url);
14
14
15 var pending = [];
15 var pending = [];
runtime/Init.js+1−1
@@ -37,7 +37,7 @@ function init(display, container, module, ports, moduleToReplace) {
37 throw new Error(
37 throw new Error(
38 'The notify function has been called synchronously!\n' +
38 'The notify function has been called synchronously!\n' +
39 'This can lead to frames being dropped.\n' +
39 'This can lead to frames being dropped.\n' +
40− 'Definitely report this to <https://github.com/evancz/Elm/issues>\n');
40+ 'Definitely report this to <https://github.com/elm-lang/Elm/issues>\n');
41 }
41 }
42 updateInProgress = true;
42 updateInProgress = true;
43 var timestep = Date.now();
43 var timestep = Date.now();
tests/libraries/LibraryTest.hs+4−2
@@ -45,7 +45,9 @@ main = do
45runCmd :: String -> [String] -> IO ()
45runCmd :: String -> [String] -> IO ()
46runCmd cmd args = do
46runCmd cmd args = do
47 putStrLn (cmd ++ " " ++ unwords args)
47 putStrLn (cmd ++ " " ++ unwords args)
48− (exitCode, _stdout, stderr) <- readProcessWithExitCode cmd args ""
48+ (exitCode, stdout, stderr) <- readProcessWithExitCode cmd args ""
49+ putStr stdout
50+ putStr stderr
49 case exitCode of
51 case exitCode of
50 ExitSuccess -> return ()
52 ExitSuccess -> return ()
51− ExitFailure _ -> error stderr
53+ ExitFailure _ -> exitWith exitCode
tests/libraries/Test.elm+2
@@ -10,6 +10,7 @@ import IO.Runner (Request, Response)
10import IO.Runner as Run
10import IO.Runner as Run
11
11
12import Test.Array as Array
12import Test.Array as Array
13+import Test.Char as Char
13import Test.Dict as Dict
14import Test.Dict as Dict
14import Test.Equality as Equality
15import Test.Equality as Equality
15import Test.List as List
16import Test.List as List
@@ -20,6 +21,7 @@ import Test.Trampoline as Trampoline
20tests : Test
21tests : Test
21tests = suite "Elm Standard Library Tests"
22tests = suite "Elm Standard Library Tests"
22 [ Array.tests
23 [ Array.tests
24+ , Char.tests
23 , Dict.tests
25 , Dict.tests
24 , Equality.tests
26 , Equality.tests
25 , List.tests
27 , List.tests
tests/libraries/Test/Array.elm+5−1
@@ -26,6 +26,8 @@ tests =
26 , test "length - Long" <| assertEqual 10000 (Array.length (Array.repeat 10000 0))
26 , test "length - Long" <| assertEqual 10000 (Array.length (Array.repeat 10000 0))
27 , test "push" <| assertEqual (Array.fromList [1,2,3]) (Array.push 3 (Array.fromList [1,2]))
27 , test "push" <| assertEqual (Array.fromList [1,2,3]) (Array.push 3 (Array.fromList [1,2]))
28 , test "append" <| assertEqual [42,42,81,81,81] (Array.toList (Array.append (Array.repeat 2 42) (Array.repeat 3 81)))
28 , test "append" <| assertEqual [42,42,81,81,81] (Array.toList (Array.append (Array.repeat 2 42) (Array.repeat 3 81)))
29+ , test "appendEmpty 1" <| assertEqual [1..33] (Array.toList (Array.append Array.empty (Array.fromList [1..33])))
30+ , test "appendEmpty 2" <| assertEqual [1..33] (Array.toList (Array.append (Array.fromList [1..33]) Array.empty))
29 ]
31 ]
30 getAndSetTests = suite "Get and Set"
32 getAndSetTests = suite "Get and Set"
31 [ test "get" <| assertEqual (Just 2) (Array.get 1 (Array.fromList [3,2,1]))
33 [ test "get" <| assertEqual (Just 2) (Array.get 1 (Array.fromList [3,2,1]))
@@ -48,9 +50,11 @@ tests =
48 [ test "map" <| assertEqual (Array.fromList [1,2,3]) (Array.map sqrt (Array.fromList [1,4,9]))
50 [ test "map" <| assertEqual (Array.fromList [1,2,3]) (Array.map sqrt (Array.fromList [1,4,9]))
49 , test "indexedMap 1" <| assertEqual (Array.fromList [0,5,10]) (Array.indexedMap (*) (Array.fromList [5,5,5]))
51 , test "indexedMap 1" <| assertEqual (Array.fromList [0,5,10]) (Array.indexedMap (*) (Array.fromList [5,5,5]))
50 , test "indexedMap 2" <| assertEqual [0..99] (Array.toList (Array.indexedMap always (Array.repeat 100 0)))
52 , test "indexedMap 2" <| assertEqual [0..99] (Array.toList (Array.indexedMap always (Array.repeat 100 0)))
51− , test "foldl" <| assertEqual [3,2,1] (Array.foldl (::) [] (Array.fromList [1,2,3]))
53+ , test "foldl 1" <| assertEqual [3,2,1] (Array.foldl (::) [] (Array.fromList [1,2,3]))
54+ , test "foldl 2" <| assertEqual 33 (Array.foldl (+) 0 (Array.repeat 33 1))
52 , test "foldr 1" <| assertEqual 15 (Array.foldr (+) 0 (Array.repeat 3 5))
55 , test "foldr 1" <| assertEqual 15 (Array.foldr (+) 0 (Array.repeat 3 5))
53 , test "foldr 2" <| assertEqual [1,2,3] (Array.foldr (::) [] (Array.fromList [1,2,3]))
56 , test "foldr 2" <| assertEqual [1,2,3] (Array.foldr (::) [] (Array.fromList [1,2,3]))
57+ , test "foldr 3" <| assertEqual 53 (Array.foldr (-) 54 (Array.fromList [10,11]))
54 , test "filter" <| assertEqual (Array.fromList [2,4,6]) (Array.filter (\x -> x `mod` 2 == 0) (Array.fromList [1..6]))
58 , test "filter" <| assertEqual (Array.fromList [2,4,6]) (Array.filter (\x -> x `mod` 2 == 0) (Array.fromList [1..6]))
55 ]
59 ]
56 nativeTests = suite "Conversion to JS Arrays"
60 nativeTests = suite "Conversion to JS Arrays"
tests/libraries/Test/Char.elmnew file+15
@@ -0,0 +1,15 @@
1+module Test.Char (tests) where
2+
3+import Char
4+
5+import ElmTest.Assertion (..)
6+import ElmTest.Test (..)
7+
8+tests : Test
9+tests =
10+ suite "Char"
11+ [ test "toUpper" <| assertEqual 'C' <| Char.toUpper 'c'
12+ , test "toLower" <| assertEqual 'c' <| Char.toLower 'C'
13+ , test "toLocaleUpper" <| assertEqual 'C' <| Char.toLocaleUpper 'c'
14+ , test "toLocaleLower" <| assertEqual 'c' <| Char.toLocaleLower 'C'
15+ ]