on master help sign in
List module dependencies in elm and js code.

Planning on having the compiler crawl through to determine dependencies, then compile everything in an appropriate order. This will also let me print out compiler progress in a reasonable order.

commitd53cecf3ba4419514524e7e8e115ce7048be2187 authorevancz <info@elm-lang.org> dateSat 23 Feb 2013, 00:19 (14 years ago) parentc710179
25 files changed+258−156
core/Color.elm+4−4 core/Date.elm+2 core/HTTP.elm+2 core/Keyboard.elm+4 core/Keyboard/Raw.elm+7 core/List.elm+22−22 core/Mouse.elm+2 core/Native/Color.js+2−2 core/Native/Date.js+10−5 core/Native/HTTP.js+9−3 core/Native/Keyboard.js+8−2 core/Native/Keyboard/Raw.js+9−2 core/Native/List.js+2−4 core/Native/Mouse.js+21−13 core/Native/Random.js+13−20 core/Native/Time.js+16−50 core/Native/Touch.js+9−4 core/Native/WebSocket.js+10−4 core/Native/Window.js+15−21 core/Random.elm+16 core/Set.elm+2 core/Time.elm+52 core/Touch.elm+2 core/WebSocket.elm+2 core/Window.elm+17
core/Color.elm+4−4
@@ -8,7 +8,7 @@ module Graphics.Color (rgba,rgb,hsva,hsv,
88 violet,forestGreen,
99 black,white,gray,grey) where
1010
11−import Native.Color as Native
11+import Native.Color
1212
1313data Color = Color Int Int Int Float
1414
@@ -39,6 +39,6 @@ purple = Color 128 0 128 1
3939forestGreen = Color 34 139 34 1
4040violet = Color 238 130 238 1
4141
42−complement = Native.complement
43−hsva = Native.hsva
44−hsv = Native.hsv
42+complement = Native.Color.complement
43+hsva = Native.Color.hsva
44+hsv = Native.Color.hsv
core/Date.elm+2
@@ -1,6 +1,8 @@
11
22module Date where
33
4+import Native.Date
5+
46data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
57
68data Month = Jan | Feb | Mar | Apr
core/HTTP.elm+2
@@ -4,6 +4,8 @@
44
55module HTTP where
66
7+import Native.HTTP
8+
79-- The datatype for responses. Success contains only the returned message.
810-- Failures contain both an error code and an error message.
911data Response a = Success a | Waiting | Failure Int String
core/Keyboard.elm+4
@@ -4,6 +4,10 @@
44
55module Keyboard where
66
7+import Native.Keyboard
8+
9+type KeyCode = Int
10+
711-- A signal of records indicating which arrow keys are pressed.
812--
913-- `{ x = 0, y = 0 }` when pressing no arrows.
core/Keyboard/Raw.elm+7
@@ -1,5 +1,12 @@
11
22module Keyboard.Raw where
33
4+import Native.Keyboard.Raw
5+
6+type KeyCode = Int
7+
8+keysDown : Signal [KeyCode]
49keysDown = Native.Keyboard.Raw.keysDown
10+
11+charPressed : Signal (Maybe Char)
512charPressed = Native.Keyboard.Raw.charPressed
core/List.elm+22−22
@@ -1,64 +1,64 @@
11
22module List where
33
4−import Native.List as Native
4+import Native.List
55
66head : [a] -> a
7−head = Native.head
7+head = Native.List.head
88
99tail : [a] -> [a]
10−tail = Native.tail
10+tail = Native.List.tail
1111
1212last : [a] -> a
13−last = Native.last
13+last = Native.List.last
1414
1515map : (a -> b) -> [a] -> [b]
16−map = Native.map
16+map = Native.List.map
1717
1818foldl : (a -> b -> b) -> b -> [a] -> b
19−foldl = Native.foldl
19+foldl = Native.List.foldl
2020
2121foldr : (a -> b -> b) -> b -> [a] -> b
22−foldr = Native.foldr
22+foldr = Native.List.foldr
2323
2424foldl1 : (a -> a -> a) -> [a] -> a
25−foldl1 = Native.foldl1
25+foldl1 = Native.List.foldl1
2626
2727foldr1 : (a -> a -> a) -> [a] -> a
28−foldr1 = Native.foldr1
28+foldr1 = Native.List.foldr1
2929
3030scanl : (a -> b -> b) -> b -> [a] -> [b]
31−scanl = Native.scanl
31+scanl = Native.List.scanl
3232
3333scanl1 : (a -> a -> a) -> [a] -> [a]
34−scanl1 = Native.scanl1
34+scanl1 = Native.List.scanl1
3535
3636filter : (a -> Bool) -> [a] -> [a]
37−filter = Native.filter
37+filter = Native.List.filter
3838
3939length : [a] -> Int
40−length = Native.length
40+length = Native.List.length
4141
4242reverse : [a] -> [a]
43−reverse = Native.reverse
43+reverse = Native.List.reverse
4444
4545concat : [[a]] -> [a]
46−concat = Native.foldr (++) []
46+concat = Native.List.foldr (++) []
4747
4848concatMap : (a -> [b]) -> [a] -> [b]
49−concatMap f = concat . Native.map f
49+concatMap f = concat . Native.List.map f
5050
5151all : (a -> Bool) -> [a] -> Bool
52−all pred = Native.all
52+all pred = Native.List.all
5353
5454any : (a -> Bool) -> [a] -> Bool
55−any = Native.any
55+any = Native.List.any
5656
5757and : [Bool] -> Bool
58−and = Native.all id
58+and = Native.List.all id
5959
6060or : [Bool] -> Bool
61−or = Native.any id
61+or = Native.List.any id
6262
6363sum = foldl (+) 0
6464product = foldl (*) 1
@@ -73,10 +73,10 @@ partition pred lst =
7373 if pred x then (x::as,bs) else (as,x::bs)
7474
7575zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
76−zipWith = Native.zipWith
76+zipWith = Native.List.zipWith
7777
7878zip : [a] -> [b] -> [(a,b)]
79−zip = Native.zip
79+zip = Native.List.zip
8080
8181unzip : [(a,b)] -> ([a],[b])
8282unzip pairs =
core/Mouse.elm+2
@@ -1,6 +1,8 @@
11
22module Mouse where
33
4+import Native.Mouse
5+
46-- The current mouse position.
57position : Signal (Int,Int)
68position = Native.Mouse.position
core/Native/Color.js+2−2
@@ -1,5 +1,5 @@
11
2−function nativeColor() {
2+(function() {
33"use strict";
44
55function extract(c) {
@@ -62,4 +62,4 @@ Elm.Native.Color = {hsva:hsva,
6262 hsv:hsv,
6363 complement:complement,
6464 extract:extract};
65−}
65+}());
core/Native/Date.js+10−5
@@ -1,12 +1,17 @@
11
2−function nativeDate(Maybe, JS) {
2+/*
3+import Maybe
4+import JavaScript
5+*/
6+
7+(function() {
38'use strict';
49
510 function dateNow() { return new window.Date; }
611 function readDate(str) {
7− var d = new window.Date(JS.castStringToJSString(str));
8− if (isNaN(d.getTime())) return Maybe.Nothing;
9− return Maybe.Just(d);
12+ var d = new window.Date(Elm.JavaScript.castStringToJSString(str));
13+ if (isNaN(d.getTime())) return Elm.Maybe.Nothing;
14+ return Elm.Maybe.Just(d);
1015 }
1116
1217 var dayTable = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
@@ -25,4 +30,4 @@ function nativeDate(Maybe, JS) {
2530 dayOfWeek : function(d) { return { ctor:dayTable[d.getDay()] }; },
2631 };
2732
28−}
33+}());
core/Native/HTTP.js+9−3
@@ -1,6 +1,12 @@
11
2−function nativeHTTP() {
3− "use strict";
2+/*
3+import JavaScript
4+import List
5+import Signal
6+*/
7+
8+(function() {
9+ 'use strict';
410
511 function registerReq(queue,responses) { return function(req) {
612 if (req.url !== "") { sendReq(queue,responses,req); }
@@ -53,4 +59,4 @@ function nativeHTTP() {
5359 }
5460
5561 Elm.Native.HTTP = {send:send};
56−}
62+}());
core/Native/Keyboard.js+8−2
@@ -1,4 +1,10 @@
1−function nativeKeyboard() {
1+/*
2+import Signal
3+import Keyboard.Raw
4+import List
5+*/
6+
7+(function() {
28 'use strict';
39
410 function keySignal(f) {
@@ -31,4 +37,4 @@ function nativeKeyboard() {
3137
3238 Elm.Native.Keyboard = { isDown:is, dir:dir };
3339
34−}
40+}());
core/Native/Keyboard/Raw.js+9−2
@@ -1,4 +1,11 @@
1−function nativeKeyboardRaw() {
1+/*
2+import Signal
3+import List
4+*/
5+
6+(function() {
7+ 'use strict';
8+
29 var keysDown = Elm.Signal.constant(Elm.Native.List.Nil);
310 var charPressed = Elm.Signal.constant(Elm.Maybe.Nothing);
411
@@ -30,4 +37,4 @@ function nativeKeyboardRaw() {
3037 });
3138
3239 Elm.Native.Keyboard.Raw = {keysDown:keysDown, charPressed:charPressed};
33−}
40+}());
core/Native/List.js+2−4
@@ -1,4 +1,4 @@
1−function nativeList() {
1+(function() {
22 "use strict";
33
44 var Nil = { ctor:'Nil' };
@@ -189,8 +189,6 @@ function nativeList() {
189189 }
190190 }
191191
192− function concatA(
193−
194192 Elm.Native.List = {
195193 head:head,
196194 tail:tail,
@@ -215,4 +213,4 @@ function nativeList() {
215213 sort:sort,
216214 take:take,
217215 drop:drop};
218−}
216+}());
core/Native/Mouse.js+21−13
@@ -1,6 +1,14 @@
1+/*
2+import Signal
3+import Native.Misc
4+*/
15
2−function nativeMouse(elm) {
3− var position = Elm.Signal.constant(Value.Tuple(0,0));
6+(function() {
7+ 'use strict';
8+
9+ var Misc = Elm.Native.Misc;
10+
11+ var position = Elm.Signal.constant(Misc.Tuple(0,0));
412 position.defaultNumberOfKids = 2;
513
614 // do not get rid of x and y. By setting their default number
@@ -13,7 +21,7 @@ function nativeMouse(elm) {
1321
1422 var isDown = Elm.Signal.constant(false);
1523 var isClicked = Elm.Signal.constant(false);
16− var clicks = Elm.Signal.constant(Value.Tuple());
24+ var clicks = Elm.Signal.constant(Misc.Tuple());
1725
1826 function getXY(e) {
1927 var posx = 0;
@@ -28,27 +36,27 @@ function nativeMouse(elm) {
2836 posy = e.clientY + document.body.scrollTop +
2937 document.documentElement.scrollTop;
3038 }
31− return Value.Tuple(posx, posy);
39+ return Misc.Tuple(posx, posy);
3240 }
3341
34− Value.addListener(document, 'click', function(e) {
42+ Misc.addListener(document, 'click', function(e) {
3543 var hasListener1 = Dispatcher.notify(isClicked.id, true);
36− var hasListener2 = Dispatcher.notify(clicks.id, Value.Tuple());
44+ var hasListener2 = Dispatcher.notify(clicks.id, Misc.Tuple());
3745 Dispatcher.notify(isClicked.id, false);
3846 if (!hasListener1 && !hasListener2)
3947 this.removeEventListener('click',arguments.callee,false);
4048 });
41− Value.addListener(document, 'mousedown', function(e) {
49+ Misc.addListener(document, 'mousedown', function(e) {
4250 var hasListener = Dispatcher.notify(isDown.id, true);
4351 if (!hasListener)
4452 this.removeEventListener('mousedown',arguments.callee,false);
4553 });
46− Value.addListener(document, 'mouseup', function(e) {
54+ Misc.addListener(document, 'mouseup', function(e) {
4755 var hasListener = Dispatcher.notify(isDown.id, false);
4856 if (!hasListener)
4957 this.removeEventListener('mouseup',arguments.callee,false);
5058 });
51− Value.addListener(document, 'mousemove', function(e) {
59+ Misc.addListener(document, 'mousemove', function(e) {
5260 var hasListener = Dispatcher.notify(position.id, getXY(e));
5361 if (!hasListener)
5462 this.removeEventListener('mousemove',arguments.callee,false);
@@ -57,17 +65,17 @@ function nativeMouse(elm) {
5765 var clickedOn = function(elem) {
5866 var node = Render.render(elem);
5967 var click = Elm.Signal.constant(false);
60− Value.addListener(node, 'click', function(e) {
68+ Misc.addListener(node, 'click', function(e) {
6169 Dispatcher.notify(click.id, true);
6270 Dispatcher.notify(click.id, false);
6371 });
64− return Value.Tuple(Value.wrap(node), click);
72+ return Misc.Tuple(Misc.wrap(node), click);
6573 };
66− elm.Native.Mouse = {position: position,
74+ Elm.Native.Mouse = {position: position,
6775 x:x,
6876 y:y,
6977 isClicked: isClicked,
7078 isDown: isDown,
7179 clicks: clicks,
7280 isClickedOn: clickedOn};
73−}
81+}());
core/Native/Random.js+13−20
@@ -1,29 +1,22 @@
1−/*! Random
2− !*/
31
4−Elm.Random = function() {
5− /*[In a Range]*/
2+/*
3+import Signal
4+*/
65
7− /** inRange : Int -> Int -> Signal Int
8− Given a range from low to high, this produces a random number
9− between 'low' and 'high' inclusive. The value in the signal does
10− not change after the page has loaded.
11− **/
12− var inRange = function(min) { return function(max) {
6+(function() {
7+
8+ function inRange(min) { return function(max) {
139 return Elm.Signal.constant(Math.floor(Math.random() * (max-min+1)) + min);
1410 };
15− };
11+ }
1612
17− /** randomize : Int -> Int -> Signal a -> Signal Int
18− Given a range from low to high and a signal of values, this produces
19− a new signal that changes whenever the input signal changes. The new
20− values are random number between 'low' and 'high' inclusive.
21− **/
22− var randomize = function(min) { return function(max) { return function(signal) {
13+ function randomize(min) { return function(max) { return function(signal) {
2314 function f(x) { return Math.floor(Math.random() * (max-min+1)) + min; }
2415 return Elm.Signal.lift(f)(signal);
2516 };
2617 };
27− };
28− return { inRange:inRange, randomize:randomize };
29−}();
18+ }
19+
20+ Elm.Native.Random = { inRange:inRange, randomize:randomize };
21+
22+}());
core/Native/Time.js+16−50
@@ -1,35 +1,12 @@
1−/*! Time
2−Library for working with time. Type `Time` represents some number of
3−milliseconds.
4−!*/
1+/*
2+import Signal
3+*/
54
6−Elm.Time = function() {
7−
8− /*[Times]*/
9−
10− /** hour, minute, second, ms : Time
11− Units of time, making it easier to specify things like a
12− half-second `(second / 2)`.
13− **/
5+(function() {
6+ 'use strict';
147
158 function timeNow() { return (new window.Date).getTime(); }
169
17− /*[Tickers]*/
18−
19− /** fps : Number -> Signal Time
20− Takes desired number of frames per second (fps). The resulting signal
21− gives a sequence of time deltas as quickly as possible until it reaches
22− the desired FPS. A time delta is the time between the last frame and the
23− current frame.
24− **/
25−
26− /** fpsWhen : Number -> Signal Bool -> Signal Time
27− Same as the fps function, but you can turn it on and off. Allows you
28− to do brief animations based on user input without major ineffeciencies.
29− The first time delta after a pause is always zero, no matter how long
30− the pause was. This way summing the deltas will actually give the amount
31− of time that the output signal has been running.
32− **/
3310 function fpsWhen(desiredFPS) { return function (isOn) {
3411 var msPerFrame = 1000 / desiredFPS;
3512 var prev = timeNow(), curr = prev, diff = 0, wasOn = true;
@@ -56,10 +33,6 @@ Elm.Time = function() {
5633 };
5734 }
5835
59− /** every : Time -> Signal Time
60− Takes a time interval t. The resulting signal is the current time,
61− updated every t.
62− **/
6336 function everyWhen(isOn) { return function(t) {
6437 var clock = Elm.Signal.constant(timeNow());
6538 function tellTime() { Dispatcher.notify(clock.id, timeNow()); }
@@ -90,23 +63,16 @@ Elm.Time = function() {
9063 var t = window.Date.parse(s);
9164 return isNaN(t) ? ["Nothing"] : ["Just",t];
9265 }
93− return {fpsWhen : fpsWhen,
94− fps : function(t) { return fpsWhen(t)(Elm.Signal.constant(true)); },
95− every : everyWhen(Elm.Signal.constant(true)),
96− delay : Elm.Signal.delay,
97− since : since,
98− after : after,
99− before : before,
100− hour : 3600000,
101− minute : 60000,
102− second : 1000,
103− ms : 1,
104− inHours : function(t) { return t / 3600000; },
105− inMinutes : function(t) { return t / 60000; },
106− inSeconds : function(t) { return t / 1000; },
107− inMss : function(t) { return t; },
108− toDate : function(t) { return new window.Date(t); },
109− read : read
66+ Elm.Native.Time = {
67+ fpsWhen : fpsWhen,
68+ fps : function(t) { return fpsWhen(t)(Elm.Signal.constant(true)); },
69+ every : everyWhen(Elm.Signal.constant(true)),
70+ delay : Elm.Signal.delay,
71+ since : since,
72+ after : after,
73+ before : before,
74+ toDate : function(t) { return new window.Date(t); },
75+ read : read
11076 };
11177
112−}();
78+}());
core/Native/Touch.js+9−4
@@ -1,5 +1,10 @@
1−function nativeTouch(elm) {
2− "use strict";
1+/*
2+import Signal
3+import JavaScript
4+*/
5+
6+(function() {
7+ 'use strict';
38
49 function Dict() {
510 this.keys = [];
@@ -90,5 +95,5 @@ function nativeTouch(elm) {
9095 return sig2;
9196 }();
9297
93− elm.Native.Touch = { touches: touches, taps: taps };
94−}
98+ Elm.Native.Touch = { touches: touches, taps: taps };
99+}());
core/Native/WebSocket.js+10−4
@@ -1,6 +1,12 @@
1+/*
2+import Signal
3+import JavaScript
4+import List
5+*/
6+
7+(function() {
8+ 'use strict';
19
2−function nativeWebSocket(elm) {
3− "use strict";
410 var JS = Elm.JavaScript;
511
612 function open(url) { return function(outgoing) {
@@ -29,5 +35,5 @@ function nativeWebSocket(elm) {
2935 };
3036 }
3137
32− elm.Native.WebSocket = {open:open};
33−}
38+ Elm.Native.WebSocket = {open:open};
39+}());
core/Native/Window.js+15−21
@@ -1,35 +1,29 @@
1−/*! Window !*/
1+/*
2+import Signal
3+import Native.Misc
4+*/
25
3−Elm.Window = function() {
6+(function() {
7+ 'use strict';
48
5− /*[Dimensions]*/
9+ var Misc = Elm.Native.Misc;
610
7− /** dimensions : Signal (Int,Int)
8− The current dimensions of the window (i.e. the area viewable to the
9− user, not including scroll bars).
10− **/
11− var dimensions = Elm.Signal.constant(Value.Tuple(window.innerWidth,
12− window.innerHeight));
11+ var dimensions = Elm.Signal.constant(Misc.Tuple(window.innerWidth,
12+ window.innerHeight));
1313 dimensions.defaultNumberOfKids = 2;
1414
15− /** width : Signal Int
16− The current width of the window.
17− **/
18− var width = Elm.Signal.lift(function(p){return p[1];})(dimensions);
15+ var width = Elm.Signal.lift(function(p){return p._0;})(dimensions);
1916 width.defaultNumberOfKids = 0;
2017
21− /** height : Signal Int
22− The current height of the window.
23− **/
24− var height = Elm.Signal.lift(function(p){return p[2];})(dimensions);
18+ var height = Elm.Signal.lift(function(p){return p._1;})(dimensions);
2519 height.defaultNumberOfKids = 0;
2620
27− Value.addListener(window, 'resize', function(e) {
21+ Misc.addListener(window, 'resize', function(e) {
2822 var w = document.getElementById('widthChecker').offsetWidth;
2923 var hasListener = Dispatcher.notify(dimensions.id,
30− Value.Tuple(w, window.innerHeight));
24+ Misc.Tuple(w, window.innerHeight));
3125 if (!hasListener)
3226 this.removeEventListener('resize',arguments.callee,false);
3327 });
34− return {dimensions:dimensions,width:width,height:height};
35−}();
28+ Elm.Native.Window = {dimensions:dimensions,width:width,height:height};
29+}());
core/Random.elmnew file+16
@@ -0,0 +1,16 @@
1+
2+module Random where
3+
4+import Native.Random
5+
6+-- Given a range from low to high, this produces a random number
7+-- between 'low' and 'high' inclusive. The value in the signal does
8+-- not change after the page has loaded.
9+inRange : Int -> Int -> Signal Int
10+inRange = Native.Random.inRange
11+
12+-- Given a range from low to high and a signal of values, this produces
13+-- a new signal that changes whenever the input signal changes. The new
14+-- values are random number between 'low' and 'high' inclusive.
15+randomize : Int -> Int -> Signal a -> Signal Int
16+randomize = Native.Random.randomize
core/Set.elm+2
@@ -6,6 +6,8 @@ module Set (empty,singleton,insert,remove
66 ,toList,fromList
77 ) where
88
9+import Dict as Dict
10+
911type Set t = Dict t ()
1012
1113empty : Set t
core/Time.elmnew file+52
@@ -0,0 +1,52 @@
1+-- Library for working with time. Type `Time` represents some number of
2+-- milliseconds.
3+
4+module Time where
5+
6+import Native.Time
7+
8+type Time = Float
9+
10+-- Units of time, making it easier to specify things like a
11+-- half-second `(second / 2)`.
12+
13+ms : Time
14+ms = 1
15+
16+second : Time
17+second = 1000 * ms
18+
19+minute : Time
20+minute = 60 * second
21+
22+hour : Time
23+hour = 60 * minute
24+
25+inMss : Time -> Float
26+inMss t = t
27+
28+inSeconds : Time -> Float
29+inSeconds t = t / second
30+
31+inMinutes : Time -> Float
32+inMinutes t = t / minute
33+
34+inHours : Time -> Float
35+inHours t = t / hour
36+
37+-- Takes desired number of frames per second (fps). The resulting signal
38+-- gives a sequence of time deltas as quickly as possible until it reaches
39+-- the desired FPS. A time delta is the time between the last frame and the
40+-- current frame.
41+fps : Number -> Signal Time
42+
43+-- Same as the fps function, but you can turn it on and off. Allows you
44+-- to do brief animations based on user input without major ineffeciencies.
45+-- The first time delta after a pause is always zero, no matter how long
46+-- the pause was. This way summing the deltas will actually give the amount
47+-- of time that the output signal has been running.
48+fpsWhen : Number -> Signal Bool -> Signal Time
49+
50+-- Takes a time interval t. The resulting signal is the current time,
51+-- updated every t.
52+every : Time -> Signal Time
core/Touch.elm+2
@@ -3,6 +3,8 @@
33
44module Touch where
55
6+import Native.Touch
7+
68type Touch = { x:Int, y:Int, id:Int, x0:Int, y0:Int, t0:Time }
79
810-- A list of touches. Each ongoing touch is represented by a set of
core/WebSocket.elm+2
@@ -3,6 +3,8 @@
33
44module WebSocket where
55
6+import Native.WebSocket
7+
68-- Create a web-socket. The first argument is the URL of the desired
79-- web-socket server. The input signal holds the outgoing messages,
810-- and the resulting signal contains the incoming ones.
core/Window.elmnew file+17
@@ -0,0 +1,17 @@
1+
2+module Window where
3+
4+import Native.Window
5+
6+-- The current dimensions of the window (i.e. the area viewable to the
7+-- user, not including scroll bars).
8+dimensions : Signal (Int,Int)
9+dimensions = Native.Window.dimensions
10+
11+-- The current width of the window.
12+width : Signal Int
13+width = Native.Window.width
14+
15+-- The current height of the window.
16+height : Signal Int
17+height = Native.Window.height