on master help sign in
Add a number of core modules, begin defining module names in .js files.
389a6f5evancz
core/Dict.elm+3−2
@@ -8,7 +8,8 @@ module Dict (empty,singleton,insert
8 ,toList,fromList
8 ,toList,fromList
9 ) where
9 ) where
10
10
11−import Maybe (isJust)
11+import Maybe as Maybe
12+import JavaScript as JavaScript
12
13
13data NColor = Red | Black
14data NColor = Red | Black
14
15
@@ -148,7 +149,7 @@ find k t =
148
149
149-- Does t contain k?
150-- Does t contain k?
150member : k -> RBTree k v -> Bool
151member : k -> RBTree k v -> Bool
151−member k t = isJust $ lookup k t
152+member k t = Maybe.isJust $ lookup k t
152
153
153rotateLeft : RBTree k v -> RBTree k v
154rotateLeft : RBTree k v -> RBTree k v
154rotateLeft t =
155rotateLeft t =
core/Color.elm → core/Graphics/Color.elmrenamed

The content is the same.

core/Element.elm → core/Graphics/Element.elmrenamed

The content is the same.

core/Form.elm → core/Graphics/Form.elmrenamed+26−29
@@ -1,35 +1,19 @@
1
1
2module Collage where
2module Collage where
3
3
4−data Line
5− = Start (Float,Float)
6− | Arc (Float,Float) Float (Float,Float) Path
7− | Line (Float,Float) Path
4+data Path = Path [(Float,Float)]
8− | Bezier (Float,Float) (Float,Float) (Float,Float) Path
9− | Quadratic (Float,Float) (Float,Float) Path
10
5
11−path ps = case ps of
6+path = Path
12− [] -> Start (0,0)
7+segment p1 p2 = Path [p1,p2]
13− hd:tl -> foldl Line (Start hd) tl
14
8
15−segment p1 p2 = Line p1 (Start p2)
9+data Shape = Shape [(Float,Float)]
16
10
17−start = Start
18−arcTo = Arc
19−lineTo = Line
20−bezierTo = Bezier
21−quadraticTo = Quadratic
22−
23−data Shape = Shape Line
24−
25−polygon ps = Shape (case ps of
11+polygon = Shape
26− [] -> Start (0,0)
27− hd:tl -> Line hd $ foldl Line (Start hd) tl)
28
12
29rect w h = polygon [ (0-w/2,0-h/2), (0-w/2,h/2), (w/2,h/2), (w/2,0-h/2) ]
13rect w h = polygon [ (0-w/2,0-h/2), (0-w/2,h/2), (w/2,h/2), (w/2,0-h/2) ]
30oval w h =
14oval w h =
31 let n = 50
15 let n = 50
32− f i = ( w/2 * cos (2*pi/n * i), h/2 * sin (2*pi/n * i))
16+ f i = (w/2 * cos (2*pi/n * i), h/2 * sin (2*pi/n * i))
33 in Shape $ map f [0..n-1]
17 in Shape $ map f [0..n-1]
34circle r = oval (2*r) (2*r)
18circle r = oval (2*r) (2*r)
35ngon n r =
19ngon n r =
@@ -56,12 +40,21 @@ data FillStyle
56 | LinearGradient [(Float,Color)] (Float,Float) (Float,Float)
40 | LinearGradient [(Float,Color)] (Float,Float) (Float,Float)
57 | RadialGradient [(Float,Color)] (Float,Float) Float (Float,Float) Float
41 | RadialGradient [(Float,Color)] (Float,Float) Float (Float,Float) Float
58
42
59−data LineStyle = NoLine | Line [Int] Int Float LineCap LineJoin Float FillStyle
43+-- dash pattern, dash offset, line width, cap, join, miter limit, fill style
44+type LineStyle = {
45+ width : Float,
46+ cap : LineCap,
47+ join : LineJoin,
48+ miterLimit : Float,
49+ fillStyle : FillStyle,
50+ dashing : [Int],
51+ dashOffset : Int
52+}
60
53
61data BasicForm
54data BasicForm
62− = FLine LineStyle FillStyle Line
55+ = FLine LineStyle Line
63 | FShape LineStyle FillStyle Shape
56 | FShape LineStyle FillStyle Shape
64− | FImage Int Int String
57+ | FImage Int Int Int Int String
65 | FElement Element
58 | FElement Element
66 | FGroup [Form]
59 | FGroup [Form]
67
60
@@ -78,10 +71,14 @@ linearGradient stops start end = setFillStyle (LinearGradient stops start end)
78radialGradient stops innerP innerR outerP outerR =
71radialGradient stops innerP innerR outerP outerR =
79 setFillStyle (RadialGradient stops innerP innerR outerP outerR)
72 setFillStyle (RadialGradient stops innerP innerR outerP outerR)
80
73
74+plain = { width=1, cap=Butt, join=Miter, miterLimit=10,
75+ fillStyle=...,
76+ dashing=[], dashOffset=0 }
77+
81−solid clr ln = Form [] (FLine ln)
78+solid c = Form [] . FLine c
82−dotted clr ln = Form [] (FLine ln)
79+dotted c = Form [] . FLine c
83−dashed clr ln = Form [] (FLine ln)
80+dashed c = Form [] . FLine c
84−customLine pattern clr ln = Form [] (FLine (Custom pattern) clr ln)
81+lineStyle = Form [] . FLine
85
82
86
83
87filled clr shp = Form [] (FShape shp)
84filled clr shp = Form [] (FShape shp)
core/JavaScript.elmnew file+4
@@ -0,0 +1,4 @@
1+
2+module JavaScript where
3+
4+toString = 4
core/List.elm+2−2
@@ -69,8 +69,8 @@ partition : (a -> Bool) -> [a] -> ([a],[a])
69partition pred lst =
69partition pred lst =
70 case lst of
70 case lst of
71 [] -> ([],[])
71 [] -> ([],[])
72− x::xs -> let (as,bs) = partition pred xs in
72+ x::xs -> let (bs,cs) = partition pred xs in
73− if pred x then (x::as,bs) else (as,x::bs)
73+ if pred x then (x::bs,cs) else (bs,x::cs)
74
74
75zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
75zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
76zipWith = Native.List.zipWith
76zipWith = Native.List.zipWith
core/Maybe.elmnew file+33
@@ -0,0 +1,33 @@
1+
2+module Maybe where
3+
4+import List as List
5+
6+-- The Maybe datatype. Useful when a computation may or may not
7+-- result in a value (e.g. logarithm is defined only for positive numbers).
8+data Maybe a = Just a | Nothing
9+
10+-- Apply a function to the contents of a `Maybe`.
11+-- Return default when given `Nothing`.
12+maybe : b -> (a -> b) -> Maybe a -> b
13+maybe b f m = case m of
14+ Just v -> f v
15+ Nothing -> b
16+
17+-- Check if constructed with `Just`.
18+isJust : Maybe a -> Bool
19+isJust = maybe False (\_ -> True)
20+
21+-- Check if constructed with `Nothing`.
22+isNothing : Maybe a -> Bool
23+isNothing = not . isJust
24+
25+
26+-- If `Just`, adds the value to the front of the list.
27+-- If `Nothing`, list is unchanged.
28+cons : Maybe a -> [a] -> [a]
29+cons mx xs = maybe xs (\x -> x:xs) mx
30+
31+-- Filters out Nothings and extracts the remaining values.
32+justs : [Maybe a] -> [a]
33+justs = List.foldr cons []
core/Native/Color.js+3
@@ -1,3 +1,6 @@
1+/**
2+module Native.Color where
3+**/
1
4
2(function() {
5(function() {
3"use strict";
6"use strict";
core/Native/Date.js+3−2
@@ -1,8 +1,9 @@
1+/**
2+module Native.Color where
1
3
2−/*
3import Maybe
4import Maybe
4import JavaScript
5import JavaScript
5−*/
6+**/
6
7
7(function() {
8(function() {
8'use strict';
9'use strict';
core/Native/List.js+34
@@ -1,3 +1,7 @@
1+ /**
2+ module Native.List where
3+ **/
4+
1(function() {
5(function() {
2 "use strict";
6 "use strict";
3
7
@@ -25,6 +29,29 @@
25 return out;
29 return out;
26 }
30 }
27
31
32+ function range(lo,hi) {
33+ var lst = Nil;
34+ if (lo <= hi) {
35+ do { lst = Cons(hi,lst) } while (hi-->lo);
36+ }
37+ return lst
38+ }
39+
40+ function append(xs,ys) {
41+ if (typeof xs === "string") { return xs.concat(ys); }
42+ if (xs.ctor === "Nil") { return ys; }
43+ var root = Elm.Native.List.Cons(xs._0. Elm.Native.List.Nil);
44+ var curr = root;
45+ xs = xs._1;
46+ while (xs.ctor==="Cons") {
47+ curr._1 = Elm.Native.List.Cons(xs._0. Elm.Native.List.Nil);
48+ xs = xs._1;
49+ curr = curr._1;
50+ }
51+ curr._1 = ys;
52+ return root;
53+ }
54+
28 function head(v) { v.ctor === "Nil" ? throwError('head') : return v._0; }
55 function head(v) { v.ctor === "Nil" ? throwError('head') : return v._0; }
29 function tail(v) { v.ctor === "Nil" ? throwError('tail') : return v._1; }
56 function tail(v) { v.ctor === "Nil" ? throwError('tail') : return v._1; }
30
57
@@ -190,6 +217,13 @@
190 }
217 }
191
218
192 Elm.Native.List = {
219 Elm.Native.List = {
220+ Nil:Nil,
221+ Cons:Cons,
222+ toArray:toArray,
223+ fromArray:fromArray,
224+ range:range,
225+ append:append,
226+
193 head:head,
227 head:head,
194 tail:tail,
228 tail:tail,
195 last:last,
229 last:last,
core/Native/Misc.js+9−34
@@ -1,5 +1,7 @@
1
1
2/*
2/*
3+module Native.Misc where
4+
3import List
5import List
4import Maybe
6import Maybe
5import JavaScript
7import JavaScript
@@ -10,7 +12,7 @@ import JSON
10(function(){
12(function(){
11 'use strict';
13 'use strict';
12
14
13− var eq = function(x,y) {
15+ function eq(x,y) {
14 if (typeof x === "object") {
16 if (typeof x === "object") {
15 if (x !== null && '_' in x) {
17 if (x !== null && '_' in x) {
16 for (var i in x) { if (x[i] != y[i]) return false; }
18 for (var i in x) { if (x[i] != y[i]) return false; }
@@ -25,7 +27,7 @@ import JSON
25 return true;
27 return true;
26 }
28 }
27 return x === y;
29 return x === y;
28− };
30+ }
29
31
30 var Tuple0 = { ctor: "Tuple0" }
32 var Tuple0 = { ctor: "Tuple0" }
31 function Tuple2(x,y) { return { ctor = "Tuple2", _0:x, _1:y }; }
33 function Tuple2(x,y) { return { ctor = "Tuple2", _0:x, _1:y }; }
@@ -219,39 +221,15 @@ import JSON
219 }
221 }
220 return v+"";
222 return v+"";
221 };
223 };
222− var show = function(v) { return str(toString(v)); };
224+ var show = function(v) { return Elm.Native.List.fromArray(toString(v)); };
223− var append = function(xs,ys) {
224− if (typeof xs === "string" && typeof ys === "string") {
225− return xs.concat(ys);
226− }
227− if (xs.ctor === "Nil") {
228− return ys;
229− }
230− var root = Elm.Native.List.Cons(xs._0. Elm.Native.List.Nil);
231− var curr = root;
232− xs = xs._1;
233− while (xs.ctor==="Cons") {
234− curr._1 = Elm.Native.List.Cons(xs._0. Elm.Native.List.Nil);
235− xs = xs._1;
236− curr = curr._1;
237− }
238− curr._1 = ys;
239− return root;
240− };
241
225
242− var str = function(s) {
226+ /*
243− var out = Elm.Native.List.Nil;
244− for (var i = s.length; i--; ) {
245− out = Elm.Native.List.Cons(s[i], out);
246− }
247− return out;
248− };
249−
250 function wrap(elem) {
227 function wrap(elem) {
251 var p = Value.getSize(elem);
228 var p = Value.getSize(elem);
252 return ['Element', Guid.guid(), ["EHtml",elem],
229 return ['Element', Guid.guid(), ["EHtml",elem],
253 p.ctor, p._0, 1, Elm.Maybe.Nothing, Elm.Maybe.Nothing];
230 p.ctor, p._0, 1, Elm.Maybe.Nothing, Elm.Maybe.Nothing];
254 }
231 }
232+ */
255 var addListener = function() {
233 var addListener = function() {
256 if(document.addEventListener) {
234 if(document.addEventListener) {
257 return function(element, event, handler) {
235 return function(element, event, handler) {
@@ -266,18 +244,15 @@ import JSON
266
244
267 Elm.Native.Misc = {
245 Elm.Native.Misc = {
268 eq:eq,
246 eq:eq,
269− str:str,
270 show:show,
247 show:show,
271− Tuple:Tuple,
248+ Tuple0:Tuple0,
272− append:append,
249+ Tuple2:Tuple2,
273− listToArray:listToArray,
274 toText : toText,
250 toText : toText,
275 properEscape : properEscape,
251 properEscape : properEscape,
276 getTextSize : getTextSize,
252 getTextSize : getTextSize,
277 getSize : getSize,
253 getSize : getSize,
278 getExcess : getExcess,
254 getExcess : getExcess,
279 groupForms : groupForms,
255 groupForms : groupForms,
280− wrap : wrap,
281 addListener : addListener
256 addListener : addListener
282 };
257 };
283}());
258}());
core/Native/Time.js+2−1
@@ -1,5 +1,6 @@
1/*
1/*
2import Signal
2import Signal
3+import Maybe
3*/
4*/
4
5
5(function() {
6(function() {
@@ -61,7 +62,7 @@ import Signal
61 }
62 }
62 function read(s) {
63 function read(s) {
63 var t = window.Date.parse(s);
64 var t = window.Date.parse(s);
64− return isNaN(t) ? ["Nothing"] : ["Just",t];
65+ return isNaN(t) ? Elm.Maybe.Nothing : Elm.Maybe.Just(t);
65 }
66 }
66 Elm.Native.Time = {
67 Elm.Native.Time = {
67 fpsWhen : fpsWhen,
68 fpsWhen : fpsWhen,
core/Prelude.elmnew file+8
@@ -0,0 +1,8 @@
1+
2+module Prelude where
3+
4+import List
5+import Signal
6+
7+fst (x,y) = x
8+snd (x,y) = y