on master help sign in
Add a bunch of core Elm modules. These are not directly integrated in the compiler right now.
e7cadafevancz
core-elm/Color.elmnew file+22
@@ -0,0 +1,22 @@
1+
2+module Graphics.Color
3+ (rgba,rgb
4+ ,red,green,blue
5+ ,yellow,cyan,magenta
6+ ,black,white,gray,grey) where
7+
8+data Color = Color Int Int Int Float
9+
10+rgba = Color
11+rgb r g b = Color r g b 1
12+
13+red = Color 255 0 0 1
14+green = Color 0 255 0 1
15+blue = Color 0 0 255 1
16+yellow = Color 255 255 0 1
17+cyan = Color 0 255 255 1
18+magenta = Color 255 0 255 1
19+black = Color 0 0 0 1
20+white = Color 255 255 255 1
21+gray = Color 128 128 128 1
22+grey = Color 128 128 128 1
core-elm/Element.elmnew file+195
@@ -0,0 +1,195 @@
1+
2+module Graphics.Element
3+ (left,right,down,up,inward,outward
4+ ,topLeft,topRight,bottomLeft,bottomRight
5+ ,midLeft,midRight,midTop,midBottom
6+ ,middle,absolute,relative
7+ ,topLeftAt,topRightAt,bottomLeftAt,bottomRightAt
8+ ,width,height,size,widthOf,heightOf,sizeOf
9+ ,color,opacity
10+ ,text,image,fittedImage,video
11+ ,flow,above,below,beside,layers
12+ ,collage,spacer,container
13+ ,line,segment
14+ ,polygon,ngon,rect,oval,circle
15+ ,solid,dotted,dashed,customLine
16+ ,filled,outlined,customOutline,textured
17+ ,sprite,toForm
18+ ,rotate,scale,move
19+ ) where
20+
21+import Graphics.Color
22+
23+data Direction = DLeft | DRight | DUp | DDown | DIn | DOut
24+
25+left = DLeft
26+right = DRight
27+down = DDown
28+up = DUp
29+inward = DIn
30+outward = DOut
31+
32+data Pos1 = Absolute Int | Relative Float
33+data Pos2 = Near | Mid | Far
34+
35+data Position
36+ = Position Pos2 Pos2
37+ | PositionAt Pos1 Pos1
38+ | PositionTL Pos1 Pos1
39+ | PositionTR Pos1 Pos1
40+ | PositionBL Pos1 Pos1
41+ | PositionBR Pos1 Pos1
42+
43+topLeft = Position Near Near
44+topRight = Position Far Near
45+bottomLeft = Position Near Far
46+bottomRight = Position Far Far
47+
48+midLeft = Position Near Mid
49+midRight = Position Far Mid
50+midTop = Position Mid Near
51+midBottom = Position Mid Far
52+
53+middle = Position Mid Mid
54+
55+middleAt = PositionAt
56+topLeftAt = PositionTL
57+topRightAt = PositionTR
58+bottomLeftAt = PositionBL
59+bottomRightAt = PositionBR
60+
61+absolute = Absolute
62+relative = Relative
63+
64+data Element = Element Int BasicElement Int Int Float (Maybe Color) (Just String)
65+
66+newElement = Element 0
67+basicNewElement e w h = Element 0 e w h 1 Nothing Nothing
68+
69+data BasicElement
70+ = EText Text Text
71+ | EImage String
72+ | EVideo String
73+ | EFittedImage String
74+ | EFlow Direction [Element]
75+ | ECollage Int Int [Form]
76+ | EEmpty
77+ | EContainer Position Element
78+
79+width w' (Element _ e w h o c l) =
80+ case e of
81+ { EText _ -> newElement e w' h o c l
82+ ; EImage _ -> newElement e w' h o c l
83+ ; EVideo _ -> newElement e w' h o c l
84+ ; _ -> newElement e w' h o c l }
85+height h' (Element _ e w h o c l) =
86+ case e of
87+ { EText _ -> newElement e w h' o c l
88+ ; EImage _ -> newElement e w h' o c l
89+ ; EVideo _ -> newElement e w h' o c l
90+ ; _ -> newElement e w h' o c l }
91+size w' h' (Element _ e w h o c l) = newElement e w' h' o c l
92+opacity o' (Element _ e w h o c l) = newElement e w h o' c l
93+color c' (Element _ e w h o c l) = newElement e w h o (Just c') l
94+link l' (Element _ e w h o c l) = newElement e w h o c (Just l')
95+
96+widthOf (Element _ _ w _ _ _ _) = w
97+heightOf (Element _ _ _ h _ _ _) = h
98+sizeOf (Element _ _ w h _ _ _) = (w,h)
99+
100+n1 = 0-1
101+
102+text t = basicNewElement (EText t) n1 n1
103+image w h s = basicNewElement (EImage s) w h
104+video w h s = basicNewElement (EVideo s) w h
105+fittedImage w h s = basicNewElement (EFittedImage s) w h
106+
107+flow dir es =
108+ let { w = let ws = map widthOf es in
109+ case dir of { DLeft -> sum ws
110+ ; DRight -> sum ws
111+ ; _ -> maximum ws }
112+ ; h = let hs = map heightOf es in
113+ case dir of { DDown -> sum hs
114+ ; DUp -> sum hs
115+ ; _ -> maximum hs }
116+ } in basicNewElement (EFlow dir es) w h
117+
118+above e1 e2 =
119+ newElement
120+ (EFlow DDown [e1,e2])
121+ (max (widthOf e1) (widthOf e2))
122+ (heightOf e1 + heightOf e2) 1 Nothing Nothing
123+
124+below e1 e2 =
125+ basicNewElement (EFlow DDown [e2,e1])
126+ (max (widthOf e1) (widthOf e2))
127+ (heightOf e1 + heightOf e2)
128+
129+beside e1 e2 =
130+ basicNewElement (EFlow DRight [e1,e2])
131+ (widthOf e1 + widthOf e2)
132+ (max (heightOf e1) (heightOf e2))
133+
134+layers es =
135+ basicNewElement (EFlow DIn es)
136+ (maximum (map widthOf es))
137+ (maximum (map heightOf es))
138+
139+collage w h forms = basicNewElement (ECollage w h forms) w h
140+
141+spacer w h = basicNewElement EEmpty w h
142+
143+container w h pos e =
144+ basicNewElement (EContainer pos e) w h
145+
146+
147+
148+data LineStyle = Solid | Dotted | Dashed | Custom [Int]
149+data ShapeStyle = Filled | Outlined | CustomOutline [Int] | Textured String
150+
151+data Line = Line [(Float,Float)]
152+
153+line = Line
154+segment p1 p2 = Line [p1,p2]
155+
156+data Shape = Shape [(Float,Float)] (Float,Float)
157+
158+polygon = Shape
159+rect w h pos = Shape [(0-w/2,0-h/2),(0-w/2,h/2),(w/2,h/2),(w/2,0-h/2)] pos
160+oval w h pos =
161+ let n = 50 in
162+ let f i = ( w/2 * cos (2*pi/n * i), h/2 * sin (2*pi/n * i)) in
163+ Shape (map f [0..n-1]) pos
164+circle r = oval (2*r) (2*r)
165+ngon n r pos =
166+ let m = toFloat n in
167+ let f i = ( r * cos (2*pi/m * i), r * sin (2*pi/m * i)) in
168+ Shape (map f [0..n-1]) pos
169+
170+data Form = Form Float Float (Float,Float) BasicForm
171+
172+data BasicForm
173+ = FLine LineStyle Color Line
174+ | FShape ShapeStyle Color Shape
175+ | FImage Int Int String
176+ | FElement Element
177+
178+solid clr ln = Form 0 1 (0,0) (FLine Solid clr ln)
179+dotted clr ln = Form 0 1 (0,0) (FLine Dotted clr ln)
180+dashed clr ln = Form 0 1 (0,0) (FLine Dashed clr ln)
181+customLine pattern clr ln =
182+ Form 0 1 (0,0) (FLine (Custom pattern) clr ln)
183+
184+filled clr (Shape ps pos) = Form 0 1 pos (FShape Filled clr (Shape ps pos))
185+outlined clr (Shape ps pos) = Form 0 1 pos (FShape Outlined clr (Shape ps pos))
186+customOutline pattern clr (Shape ps pos) =
187+ Form 0 1 pos (FShape (CustomOutline pattern) clr (Shape ps pos))
188+textured src (Shape ps pos) = Form 0 1 pos (FShape (Textured src) black (Shape ps pos))
189+
190+sprite w h pos src = Form 0 1 pos (FImage w h src)
191+toForm pos e = Form 0 1 pos (FElement e)
192+
193+rotate t (Form theta scale pos form) = Form (t+theta) scale pos form
194+scale s (Form theta scale pos form) = Form theta (s*scale) pos form
195+move x y (Form theta scale (px,py) form) = Form theta scale (x+px,y+py) form
core-elm/List.elmnew file+59
@@ -0,0 +1,59 @@
1+
2+head (h:t) = h
3+tail (h:t) = t
4+
5+map f lst = case lst of { x:xs -> f x : map f xs; [] -> [] }
6+foldl f b lst = case lst of { x:xs -> foldl f (f x b) xs; [] -> b }
7+foldr f b lst = case lst of { x:xs -> f x (foldr f b xs); [] -> b }
8+
9+foldl1 f (x:xs) = foldl f x xs
10+foldr1 f (x:xs) = foldr f x xs
11+
12+scanl f b xs = b : (case xs of { x:xs -> scanl f (f x b) xs; [] -> [] })
13+scanl1 f lst = case lst of { x:xs -> scanl f x xs; [] -> [] }
14+
15+filter pred lst =
16+ case lst of
17+ { x:xs -> if pred x then x : filter pred xs else filter pred xs
18+ ; [] -> [] }
19+
20+length = foldl (\x c -> 1 + c) 0
21+reverse = foldl (:) []
22+
23+concat = foldr (++) []
24+concatMap f = concat . map f
25+
26+and = foldl (&&) True
27+or = foldl (||) False
28+
29+forall pred = foldl (\x acc -> acc && pred x) True
30+exists pred = foldl (\x acc -> acc || pred x) False
31+
32+sum = foldl (+) 0
33+product = foldl (*) 1
34+maximum = foldl1 max
35+minimum = foldl1 min
36+
37+partition pred lst =
38+ case lst of
39+ { x:xs -> case partition pred xs of
40+ { (as,bs) -> if pred x then (x:as,bs) else (as,x:bs) }
41+ ; [] -> ([],[]) }
42+
43+zipWith f listA listB = case (listA, listB) of
44+ { (a:as, b:bs) -> f a b : zipWith f as bs; _ -> [] }
45+
46+zip listA listB = case (listA, listB) of
47+ { (a:as, b:bs) -> (a,b) : zip as bs; _ -> [] }
48+
49+unzip pairs =
50+ case pairs of
51+ { p:ps -> case (p, unzip ps) of { ((x,y),(xs,ys)) -> (x:xs,y:ys) }
52+ ; [] -> ([],[]) }
53+
54+intersperse sep xs =
55+ case xs of { a:b:cs -> a : sep : intersperse sep (b:cs)
56+ ; a:[] -> [a] ; [] -> [] }
57+intercalate sep xs =
58+ case xs of { a:b:cs -> a ++ sep ++ intercalate sep (b:cs)
59+ ; a:[] -> a ; [] -> [] }
core-elm/Map.elmnew file+13
@@ -0,0 +1,13 @@
1+
2+empty = []
3+singleton k v = [(k,v)]
4+insert k v dict = (k,v):dict
5+
6+fst pair = let (a,b) = pair in a
7+
8+member key = exists (\pair -> fst pair == key)
9+
10+delete key = filter (\pair -> fst pair == key)
11+intersect d1 d2 = filter (\pair -> member (fst pair) d2) d1
12+difference d1 d2 = filter (\pair -> not (member (fst pair) d2)) d1
13+union d1 d2 = d1 ++ difference d2 d1