on master help sign in
Add a number of core modules, begin defining module names in .js files.
commit389a6f5309a2ab62684b85dddb5766c3a263938d authorevancz <info@elm-lang.org> dateTue 26 Feb 2013, 23:26 (14 years ago) parent45586e0
13 files changed+127−70
core/Dict.elm+3−2 core/Color.elm → core/Graphics/Color.elm core/Element.elm → core/Graphics/Element.elm core/Form.elm → core/Graphics/Form.elm+26−29 core/JavaScript.elm+4 core/List.elm+2−2 core/Maybe.elm+33 core/Native/Color.js+3 core/Native/Date.js+3−2 core/Native/List.js+34 core/Native/Misc.js+9−34 core/Native/Time.js+2−1 core/Prelude.elm+8
core/Dict.elm+3−2
@@ -8,7 +8,8 @@ module Dict (empty,singleton,insert
88 ,toList,fromList
99 ) where
1010
11−import Maybe (isJust)
11+import Maybe as Maybe
12+import JavaScript as JavaScript
1213
1314data NColor = Red | Black
1415
@@ -148,7 +149,7 @@ find k t =
148149
149150-- Does t contain k?
150151member : k -> RBTree k v -> Bool
151−member k t = isJust $ lookup k t
152+member k t = Maybe.isJust $ lookup k t
152153
153154rotateLeft : RBTree k v -> RBTree k v
154155rotateLeft 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 @@
11
22module Collage where
33
4−data Line
5− = Start (Float,Float)
6− | Arc (Float,Float) Float (Float,Float) Path
7− | Line (Float,Float) Path
8− | Bezier (Float,Float) (Float,Float) (Float,Float) Path
9− | Quadratic (Float,Float) (Float,Float) Path
4+data Path = Path [(Float,Float)]
105
11−path ps = case ps of
12− [] -> Start (0,0)
13− hd:tl -> foldl Line (Start hd) tl
6+path = Path
7+segment p1 p2 = Path [p1,p2]
148
15−segment p1 p2 = Line p1 (Start p2)
9+data Shape = Shape [(Float,Float)]
1610
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
26− [] -> Start (0,0)
27− hd:tl -> Line hd $ foldl Line (Start hd) tl)
11+polygon = Shape
2812
2913rect w h = polygon [ (0-w/2,0-h/2), (0-w/2,h/2), (w/2,h/2), (w/2,0-h/2) ]
3014oval w h =
3115 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))
3317 in Shape $ map f [0..n-1]
3418circle r = oval (2*r) (2*r)
3519ngon n r =
@@ -56,12 +40,21 @@ data FillStyle
5640 | LinearGradient [(Float,Color)] (Float,Float) (Float,Float)
5741 | RadialGradient [(Float,Color)] (Float,Float) Float (Float,Float) Float
5842
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+}
6053
6154data BasicForm
62− = FLine LineStyle FillStyle Line
55+ = FLine LineStyle Line
6356 | FShape LineStyle FillStyle Shape
64− | FImage Int Int String
57+ | FImage Int Int Int Int String
6558 | FElement Element
6659 | FGroup [Form]
6760
@@ -78,10 +71,14 @@ linearGradient stops start end = setFillStyle (LinearGradient stops start end)
7871radialGradient stops innerP innerR outerP outerR =
7972 setFillStyle (RadialGradient stops innerP innerR outerP outerR)
8073
81−solid clr ln = Form [] (FLine ln)
82−dotted clr ln = Form [] (FLine ln)
83−dashed clr ln = Form [] (FLine ln)
84−customLine pattern clr ln = Form [] (FLine (Custom pattern) clr ln)
74+plain = { width=1, cap=Butt, join=Miter, miterLimit=10,
75+ fillStyle=...,
76+ dashing=[], dashOffset=0 }
77+
78+solid c = Form [] . FLine c
79+dotted c = Form [] . FLine c
80+dashed c = Form [] . FLine c
81+lineStyle = Form [] . FLine
8582
8683
8784filled 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])
6969partition pred lst =
7070 case lst of
7171 [] -> ([],[])
72− x::xs -> let (as,bs) = partition pred xs in
73− if pred x then (x::as,bs) else (as,x::bs)
72+ x::xs -> let (bs,cs) = partition pred xs in
73+ if pred x then (x::bs,cs) else (bs,x::cs)
7474
7575zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
7676zipWith = 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+**/
14
25(function() {
36"use strict";
core/Native/Date.js+3−2
@@ -1,8 +1,9 @@
1+/**
2+module Native.Color where
13
2−/*
34import Maybe
45import JavaScript
5−*/
6+**/
67
78(function() {
89'use strict';
core/Native/List.js+34
@@ -1,3 +1,7 @@
1+ /**
2+ module Native.List where
3+ **/
4+
15(function() {
26 "use strict";
37
@@ -25,6 +29,29 @@
2529 return out;
2630 }
2731
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+
2855 function head(v) { v.ctor === "Nil" ? throwError('head') : return v._0; }
2956 function tail(v) { v.ctor === "Nil" ? throwError('tail') : return v._1; }
3057
@@ -190,6 +217,13 @@
190217 }
191218
192219 Elm.Native.List = {
220+ Nil:Nil,
221+ Cons:Cons,
222+ toArray:toArray,
223+ fromArray:fromArray,
224+ range:range,
225+ append:append,
226+
193227 head:head,
194228 tail:tail,
195229 last:last,
core/Native/Misc.js+9−34
@@ -1,5 +1,7 @@
11
22/*
3+module Native.Misc where
4+
35import List
46import Maybe
57import JavaScript
@@ -10,7 +12,7 @@ import JSON
1012(function(){
1113 'use strict';
1214
13− var eq = function(x,y) {
15+ function eq(x,y) {
1416 if (typeof x === "object") {
1517 if (x !== null && '_' in x) {
1618 for (var i in x) { if (x[i] != y[i]) return false; }
@@ -25,7 +27,7 @@ import JSON
2527 return true;
2628 }
2729 return x === y;
28− };
30+ }
2931
3032 var Tuple0 = { ctor: "Tuple0" }
3133 function Tuple2(x,y) { return { ctor = "Tuple2", _0:x, _1:y }; }
@@ -219,39 +221,15 @@ import JSON
219221 }
220222 return v+"";
221223 };
222− var show = function(v) { return str(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− };
224+ var show = function(v) { return Elm.Native.List.fromArray(toString(v)); };
241225
242− var str = function(s) {
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−
226+ /*
250227 function wrap(elem) {
251228 var p = Value.getSize(elem);
252229 return ['Element', Guid.guid(), ["EHtml",elem],
253230 p.ctor, p._0, 1, Elm.Maybe.Nothing, Elm.Maybe.Nothing];
254231 }
232+ */
255233 var addListener = function() {
256234 if(document.addEventListener) {
257235 return function(element, event, handler) {
@@ -266,18 +244,15 @@ import JSON
266244
267245 Elm.Native.Misc = {
268246 eq:eq,
269− str:str,
270247 show:show,
271− Tuple:Tuple,
272− append:append,
273− listToArray:listToArray,
248+ Tuple0:Tuple0,
249+ Tuple2:Tuple2,
274250 toText : toText,
275251 properEscape : properEscape,
276252 getTextSize : getTextSize,
277253 getSize : getSize,
278254 getExcess : getExcess,
279255 groupForms : groupForms,
280− wrap : wrap,
281256 addListener : addListener
282257 };
283258}());
core/Native/Time.js+2−1
@@ -1,5 +1,6 @@
11/*
22import Signal
3+import Maybe
34*/
45
56(function() {
@@ -61,7 +62,7 @@ import Signal
6162 }
6263 function read(s) {
6364 var t = window.Date.parse(s);
64− return isNaN(t) ? ["Nothing"] : ["Just",t];
65+ return isNaN(t) ? Elm.Maybe.Nothing : Elm.Maybe.Just(t);
6566 }
6667 Elm.Native.Time = {
6768 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