on master help sign in
Lots of tiny fixes to get the RTS working!
commita1b890adc3218f373958ddc7b3688b12952c9d47 authorevancz <info@elm-lang.org> dateTue 12 Mar 2013, 00:48 (14 years ago) parent15c35c8
29 files changed+143−128
Build.hs+10−9 compiler/Elm.cabal+2−2 compiler/src/Compiler.hs+1−1 compiler/src/Gen/CompileToJS.hs+14−21 compiler/src/Gen/GenerateHtml.hs+3−3 compiler/src/Parse/Parser.hs+2−2 compiler/src/Parse/Types.hs+16−2 libraries/Dict.elm+14−16 libraries/Graphics/Collage.elm+1−1 libraries/Graphics/Color.elm−2 libraries/Graphics/Element.elm+19−17 libraries/Graphics/LineStyle.elm+1−1 libraries/List.elm+1 libraries/Native/Date.js+2−2 libraries/Native/Error.js+5−1 libraries/Native/Graphics/Color.js+6−9 libraries/Native/List.js+1−1 libraries/Native/Prelude.js+7 libraries/Native/Show.js+3−2 libraries/Native/Signal/Signal.js+9−9 libraries/Native/Utils.js+12−4 libraries/Prelude.elm−8 libraries/Signal.elm+1−3 libraries/Time.elm−2 libraries/Touch.elm+1−1 libraries/WebSocket.elm+1−1 libraries/Window.elm−2 runtime/Init.js+2−3 runtime/Render.js+9−3
Build.hs+10−9
@@ -1,10 +1,6 @@
11-- This file compiles all library and runtime code
2−-- into elm-runtime.js. Run it with following command:
3−--
4−-- runHaskell Build.hs
5−--
6−-- Note: This does NOT compile the compiler! Run `cabal install`
7−-- from the compiler/ directory to do that.
2+-- into compiler/elm-runtime.js. It then rebuilds the compiler.
3+-- Run it with the command "runHaskell Build.hs".
84
95import System.Cmd
106import System.Directory
@@ -13,6 +9,8 @@ import System.FilePath
139import System.IO
1410import Language.Elm
1511
12+rts = "compiler" </> "elm-runtime.js"
13+
1614getFiles ext dir = do
1715 contents <- map (dir </>) `fmap` getDirectoryContents dir
1816 let files = filter (\f -> takeExtension f == ext) contents
@@ -24,7 +22,7 @@ appendJS file = do
2422 putStrLn (dropExtension file)
2523 str <- readFile file
2624 length str `seq` return ()
27− appendFile "elm-runtime.js" str
25+ appendFile rts str
2826
2927appendElm file = do
3028 system ("elm --only-js " ++ file)
@@ -33,9 +31,12 @@ appendElm file = do
3331 removeFile jsFile
3432
3533main = do
36− writeFile "elm-runtime.js" "Elm = {}; Elm.Native = {}; Elm.Native.Graphics = {}; Elm.Graphics = {};\n"
34+ writeFile rts "Elm = {}; Elm.Native = {}; Elm.Native.Graphics = {}; Elm.Graphics = {};\n"
3735 mapM_ appendJS =<< getFiles ".js" "libraries"
3836 mapM_ appendElm =<< getFiles ".elm" "libraries"
3937 mapM_ appendJS =<< getFiles ".js" "runtime"
40− putStrLn "Success building runtime and libraries!"
38+ putStrLn "\n+------------------------------------------+\
39+ \\n| Success building runtime and libraries! |\
40+ \\n+------------------------------------------+\n"
41+ system ("cabal install compiler" </> "Elm.cabal")
4142 exitSuccess
compiler/Elm.cabal+2−2
@@ -1,6 +1,6 @@
11
22Name: Elm
3−Version: 0.7.2
3+Version: 0.8
44Synopsis: The Elm language module.
55Description: Elm aims to make client-side web-development more pleasant.
66 It is a statically/strongly typed, functional reactive
@@ -22,7 +22,7 @@ Category: Compiler, Language
2222Build-type: Simple
2323
2424Extra-source-files: changelog.txt
25−Data-files: elm-runtime-0.7.2.js
25+Data-files: elm-runtime.js
2626Cabal-version: >=1.8
2727
2828source-repository head
compiler/src/Compiler.hs+1−1
@@ -47,7 +47,7 @@ elm = ELM { make = False &= help "automatically compile dependencies."
4747
4848main = do
4949 args <- cmdArgs elm
50− mini <- getDataFileName ("elm-runtime-" ++ showVersion version ++ ".js")
50+ mini <- getDataFileName "elm-runtime.js"
5151 compileArgs mini args
5252
5353compileArgs mini (ELM _ [] _ _ _ _ _ _ _) =
compiler/src/Gen/CompileToJS.hs+14−21
@@ -28,7 +28,7 @@ indent = concatMap f
2828
2929internalImports =
3030 [ ("N" , "Elm.Native"),
31− ("_" , "N.Utils(elm)"),
31+ ("_N", "N.Utils(elm)"),
3232 ("_L", "N.List(elm)"),
3333 ("_E", "N.Error(elm)"),
3434 ("_str", "N.JavaScript(elm).toString")
@@ -53,7 +53,7 @@ globalAssign n e = "\n" ++ assign' n e ++ ";"
5353assign' n e = n ++ " = " ++ e
5454
5555jsModule (Module names exports imports stmts) =
56− setup ++ globalAssign ("Elm." ++ modName) (jsFunc "elm" program)
56+ setup ("Elm":modNames) ++ globalAssign ("Elm." ++ modName) (jsFunc "elm" program)
5757 where
5858 modNames = if null names then ["Main"] else names
5959 modName = intercalate "." modNames
@@ -61,12 +61,12 @@ jsModule (Module names exports imports stmts) =
6161 body = stmtsToJS stmts
6262 defs = assign "$op" "{}"
6363 program = "\nvar " ++ usefulFuncs ++ ";" ++ defs ++ includes ++ body ++
64− "\n_ = " ++ "elm.Native." ++ modName ++ " || {};" ++
65− getExports exports stmts ++
64+ setup ("elm":"Native":modNames) ++
65+ assign "_" ("elm.Native." ++ modName ++ " || {}") ++
66+ getExports exports stmts ++ setup ("elm":modNames) ++
6667 ret (assign' ("elm." ++ modName) "_") ++ "\n"
67− setup = concatMap (\n -> globalAssign n $ n ++ " || {}") .
68− map (intercalate ".") . tail . inits $
69− take (length modNames - 1) modNames
68+ setup modNames = concatMap (\n -> globalAssign n $ n ++ " || {}") .
69+ map (intercalate ".") . tail . inits $ init modNames
7070 usefulFuncs = intercalate ", " (map (uncurry assign') internalImports)
7171
7272getExports names stmts = "\n"++ intercalate ";\n" (op : map fnPair fns)
@@ -157,14 +157,7 @@ instance ToJS Statement where
157157 , "e.value = v;"
158158 , "document.dispatchEvent(e); return v; })(", elm, ");" ]
159159 TypeAnnotation _ _ -> return ""
160− TypeAlias n _ t ->
161− case t of
162− RecordT kvs _ -> return $ "\nfunction" ++ args ++ brackets body
163− where fs = Map.keys kvs
164− args = parens (intercalate "," fs)
165− body = ret . brackets . intercalate "," $
166− map (\k -> k ++ ":" ++ k) fs
167− _ -> return ""
160+ TypeAlias n _ t -> return ""
168161
169162toJS' :: CExpr -> GuidCounter String
170163toJS' (C txt span expr) =
@@ -173,9 +166,9 @@ toJS' (C txt span expr) =
173166 Case e cases -> caseToJS span e cases
174167 _ -> toJS expr
175168
176−remove x e = "_.remove('" ++ x ++ "', " ++ e ++ ")"
177−addField x v e = "_.insert('" ++ x ++ "', " ++ v ++ ", " ++ e ++ ")"
178−setField fs e = "_.replace(" ++ jsList (map f fs) ++ ", " ++ e ++ ")"
169+remove x e = "_N.remove('" ++ x ++ "', " ++ e ++ ")"
170+addField x v e = "_N.insert('" ++ x ++ "', " ++ v ++ ", " ++ e ++ ")"
171+setField fs e = "_N.replace(" ++ jsList (map f fs) ++ ", " ++ e ++ ")"
179172 where f (x,v) = "['" ++ x ++ "'," ++ v ++ "]"
180173access x e = parens e ++ "." ++ x
181174makeRecord kvs = record `liftM` collect kvs
@@ -305,7 +298,7 @@ clauseToJS span var (Clause name vars e) = do
305298jsNil = "_L.Nil"
306299jsCons e1 e2 = "_L.Cons(" ++ e1 ++ "," ++ e2 ++ ")"
307300jsRange e1 e2 = "_L.range" ++ parens (e1 ++ "," ++ e2)
308−jsCompare e1 e2 op = parens ("_.compare(" ++ e1 ++ "," ++ e2 ++ ").ctor" ++ op)
301+jsCompare e1 e2 op = parens ("_N.compare(" ++ e1 ++ "," ++ e2 ++ ").ctor" ++ op)
309302
310303binop (o:p) e1 e2
311304 | isAlpha o || '_' == o = (o:p) ++ parens e1 ++ parens e2
@@ -317,8 +310,8 @@ binop (o:p) e1 e2
317310 "$" -> e1 ++ parens e2
318311 "." -> jsFunc "x" . ret $ e1 ++ parens (e2 ++ parens "x")
319312 "^" -> "Math.pow(" ++ e1 ++ "," ++ e2 ++ ")"
320− "==" -> "_.eq(" ++ e1 ++ "," ++ e2 ++ ")"
321− "/=" -> "!_.eq(" ++ e1 ++ "," ++ e2 ++ ")"
313+ "==" -> "_N.eq(" ++ e1 ++ "," ++ e2 ++ ")"
314+ "/=" -> "!_N.eq(" ++ e1 ++ "," ++ e2 ++ ")"
322315 "<" -> jsCompare e1 e2 "==='LT'"
323316 ">" -> jsCompare e1 e2 "==='GT'"
324317 "<=" -> jsCompare e1 e2 "!=='GT'"
compiler/src/Gen/GenerateHtml.hs+3−3
@@ -35,13 +35,13 @@ makeScript jsStyle (Right s) =
3535-- Usage example:
3636--
3737-- > generateHtml "/elm-min.js" "Some title" [elmFile|elm-source/somePage.elm|]
38−generateHtml :: String -- ^ Location of elm-min.js as expected by the browser
38+generateHtml :: String -- ^ Location of elm-runtime.js as expected by the browser
3939 -> String -- ^ The page title
4040 -> String -- ^ The elm source code.
4141 -> Html
4242generateHtml libLoc title source =
4343 case buildFromSource source of
44− Left err -> createHtml Readable libLoc title (Right $ showErr err) (H.noscript "")
44+ Left err -> createHtml Readable libLoc title (Right $ showErr err) (H.noscript "") "Elm.Main"
4545 Right modul -> modulesToHtml Readable title libLoc [] True [modul]
4646
4747
@@ -69,5 +69,5 @@ createHtml jsStyle libLoc title js noscript moduleToLoad =
6969 H.body $ do
7070 makeScript Readable (Left libLoc)
7171 makeScript jsStyle js
72− H.script ! A.type_ "text/javascript" $ "Elm.init(" ++ moduleToLoad ++ ")"
72+ H.script ! A.type_ "text/javascript" $ preEscapedToMarkup ("Elm.init(Elm." ++ moduleToLoad ++ ")" :: String)
7373 H.noscript $ preEscapedToMarkup noscript
compiler/src/Parse/Parser.hs+2−2
@@ -14,8 +14,8 @@ import Parse.Modules
1414import Parse.Foreign
1515
1616
17−statement = let defs = [ foreignDef, datatype, typeAlias, typeAnnotation ] in
18− (:[]) <$> choice defs <|> def <?> "datatype or variable definition"
17+statement = choice (typeAlias:defs) <|> def <?> "datatype or variable definition"
18+ where defs = map ((:[]) <$>) [ foreignDef, datatype, typeAnnotation ]
1919
2020freshDef = commitIf (freshLine >> (letter <|> char '_')) $ do
2121 freshLine
compiler/src/Parse/Types.hs+16−2
@@ -9,6 +9,7 @@ import Data.List (lookup)
99import Text.Parsec
1010import Text.Parsec.Indent
1111
12+import Context
1213import Parse.Library
1314import Types.Types hiding (string,parens)
1415import Guid
@@ -70,8 +71,9 @@ typeConstructor :: IParser (String, [ParseType])
7071typeConstructor = (,) <$> (capVar <?> "another type constructor")
7172 <*> spacePrefix (typeSimple <|> typeUnambiguous)
7273
73−typeAlias :: IParser Statement
74+typeAlias :: IParser [Statement]
7475typeAlias = do
76+ start <- getPosition
7577 reserved "type" <?> "type alias (type Point = {x:Int, y:Int})"
7678 forcedWS
7779 alias <- capVar
@@ -79,9 +81,21 @@ typeAlias = do
7981 whitespace ; string "=" ; whitespace
8082 let n = length args
8183 tipe <- typeExpr
84+ end <- getPosition
8285 case toTypeWith alias (zip args [1..n]) tipe of
83− Right t -> return (TypeAlias alias [1..n] t)
8486 Left msg -> fail msg
87+ Right t -> return (TypeAlias alias [1..n] t : ctor)
88+ where ctor = case tipe of
89+ RecordPT _ kvs -> [toConstructor start end alias kvs]
90+ _ -> []
91+
92+toConstructor start end alias kvs =
93+ Definition (FnDef alias args (ctxt (Record rec)))
94+ where
95+ ctxt = pos start end
96+ args = map fst kvs
97+ rec = map (\a -> (a, [], ctxt (Var a))) args
98+
8599
86100typeAnnotation :: IParser Statement
87101typeAnnotation = TypeAnnotation <$> try start <*> (toType <$> typeExpr)
libraries/Dict.elm+14−16
@@ -9,7 +9,7 @@ module Dict (empty,singleton,insert
99 ) where
1010
1111import Maybe as Maybe
12−import JavaScript as JavaScript
12+import Native.Error as Error
1313
1414data NColor = Red | Black
1515
@@ -18,8 +18,6 @@ data RBTree k v = RBNode NColor k v (RBTree k v) (RBTree k v) | RBEmpty
1818empty : RBTree k v
1919empty = RBEmpty
2020
21−raise err = throw (JavaScript.castStringToJSString err)
22−
2321{-- Helpers for checking invariants
2422
2523-- Check that the tree has an equal number of black nodes on each path
@@ -104,14 +102,14 @@ min t =
104102 case t of
105103 RBNode _ k v RBEmpty _ -> (k,v)
106104 RBNode _ _ _ l _ -> min l
107− RBEmpty -> raise "(min RBEmpty) is not defined"
105+ RBEmpty -> Error.raise "(min RBEmpty) is not defined"
108106
109107{--
110108max t =
111109 case t of
112110 { RBNode _ k v _ RBEmpty -> (k,v)
113111 ; RBNode _ _ _ _ r -> max r
114− ; RBEmpty -> raise "(max RBEmpty) is not defined"
112+ ; RBEmpty -> Error.raise "(max RBEmpty) is not defined"
115113 }
116114--}
117115
@@ -138,7 +136,7 @@ findWithDefault base k t =
138136{--
139137find k t =
140138 case t of
141− { RBEmpty -> raise "Key was not found in dictionary!"
139+ { RBEmpty -> Error.raise "Key was not found in dictionary!"
142140 ; RBNode _ k' v l r ->
143141 case compare k k' of
144142 { LT -> find k l
@@ -155,7 +153,7 @@ rotateLeft : RBTree k v -> RBTree k v
155153rotateLeft t =
156154 case t of
157155 RBNode cy ky vy a (RBNode cz kz vz b c) -> RBNode cy kz vz (RBNode Red ky vy a b) c
158− _ -> raise "rotateLeft of a node without enough children"
156+ _ -> Error.raise "rotateLeft of a node without enough children"
159157
160158-- rotateRight -- the reverse, and
161159-- makes Y have Z's color, and makes Z Red.
@@ -163,7 +161,7 @@ rotateRight : RBTree k v -> RBTree k v
163161rotateRight t =
164162 case t of
165163 RBNode cz kz vz (RBNode cy ky vy a b) c -> RBNode cz ky vy a (RBNode Red kz vz b c)
166− _ -> raise "rotateRight of a node without enough children"
164+ _ -> Error.raise "rotateRight of a node without enough children"
167165
168166rotateLeftIfNeeded : RBTree k v -> RBTree k v
169167rotateLeftIfNeeded t =
@@ -186,7 +184,7 @@ color_flip t =
186184 RBNode (otherColor c1) bk bv
187185 (RBNode (otherColor c2) ak av la ra)
188186 (RBNode (otherColor c3) ck cv lc rc)
189− _ -> raise "color_flip called on a RBEmpty or RBNode with a RBEmpty child"
187+ _ -> Error.raise "color_flip called on a RBEmpty or RBNode with a RBEmpty child"
190188
191189color_flipIfNeeded : RBTree k v -> RBTree k v
192190color_flipIfNeeded t =
@@ -217,10 +215,10 @@ insert k v t =
217215 in ensureBlackRoot (ins t)
218216{--
219217 if not (invariants_hold t) then
220− raise "invariants broken before insert"
218+ Error.raise "invariants broken before insert"
221219 else (let new_t = ensureBlackRoot (ins t) in
222220 if not (invariants_hold new_t) then
223− raise "invariants broken after insert"
221+ Error.raise "invariants broken after insert"
224222 else new_t)
225223--}
226224
@@ -311,14 +309,14 @@ remove k t =
311309 eq t = case t of { RBNode _ k' _ _ _ -> k == k' ; _ -> False }
312310 delLT t = case moveRedLeftIfNeeded t of
313311 RBNode c k' v l r -> fixUp (RBNode c k' v (del l) r)
314− RBEmpty -> raise "delLT on RBEmpty"
312+ RBEmpty -> Error.raise "delLT on RBEmpty"
315313 delEQ t = case t of -- Replace with successor
316314 RBNode c _ _ l r -> let (k',v') = min r in
317315 fixUp (RBNode c k' v' l (deleteMin r))
318− RBEmpty -> raise "delEQ called on a RBEmpty"
316+ RBEmpty -> Error.raise "delEQ called on a RBEmpty"
319317 delGT t = case t of
320318 RBNode c k' v l r -> fixUp (RBNode c k' v l (del r))
321− RBEmpty -> raise "delGT called on a RBEmpty"
319+ RBEmpty -> Error.raise "delGT called on a RBEmpty"
322320 del t = case t of
323321 RBEmpty -> RBEmpty
324322 RBNode _ k' _ _ _ ->
@@ -330,10 +328,10 @@ remove k t =
330328 in if member k t then ensureBlackRoot (del t) else t
331329{--
332330 if not (invariants_hold t) then
333− raise "invariants broken before remove"
331+ Error.raise "invariants broken before remove"
334332 else (let t' = ensureBlackRoot (del t) in
335333 if invariants_hold t' then t' else
336− raise "invariants broken after remove")
334+ Error.raise "invariants broken after remove")
337335--}
338336
339337map : (a -> b) -> RBTree k a -> RBTree k b
libraries/Graphics/Collage.elm+1−1
@@ -2,7 +2,7 @@
22module Graphics.Collage where
33
44import Either
5−import Graphics.LineStyle
5+import Graphics.LineStyle as LS
66import Geometry
77
88data Transform
libraries/Graphics/Color.elm−2
@@ -9,8 +9,6 @@ module Graphics.Color (rgba,rgb,hsva,hsv,
99 black,white,gray,grey,
1010 linear,radial) where
1111
12−import Native.Graphics.Color as C
13−
1412data Color = Color Int Int Int Float
1513
1614rgba = Color
libraries/Graphics/Element.elm+19−17
@@ -1,21 +1,22 @@
11
2−module Grapics.Element (widthOf, heightOf, sizeOf,
3− width, height, opacity, color, tag, link,
4− image, fittedImage, croppedImage,
5− flow, up, down, left, right, inward, outward,
6− above, below, beside, layers,
7− container, absolute, relative,
8− middle, topLeft, topRight, bottomLeft, bottomRight,
9− midLeft, midRight, midTop, midBottom, middleAt,
10− topLeftAt, topRightAt, bottomLeftAt, bottomRightAt,
11− midLeftAt, midRightAt, midTopAt, midBottomAt,
12− spacer
13− ) where
2+module Graphics.Element (widthOf, heightOf, sizeOf,
3+ width, height, opacity, color, tag, link,
4+ image, fittedImage, croppedImage,
5+ flow, up, down, left, right, inward, outward,
6+ above, below, beside, layers,
7+ container, absolute, relative,
8+ middle, topLeft, topRight, bottomLeft, bottomRight,
9+ midLeft, midRight, midTop, midBottom, middleAt,
10+ topLeftAt, topRightAt, bottomLeftAt, bottomRightAt,
11+ midLeftAt, midRightAt, midTopAt, midBottomAt,
12+ spacer
13+ ) where
1414
1515import Native.Utils (guid)
1616import JavaScript as JS
1717import List as List
18−import Graphics.Color
18+import Graphics.Color as Color
19+import Maybe (Just, Nothing)
1920
2021type Properties = {
2122 id : Int,
@@ -36,15 +37,16 @@ sizeOf e = (e.props.width, e.props.height)
3637width w e = let p = e.props in { element=e.element, props={p| width <- w} }
3738height h e = let p = e.props in { element=e.element, props={p| height <- h} }
3839opacity o e = let p = e.props in { element=e.element, props={p| opacity <- o} }
39−color c e = let p = e.props in { element=e.element, props={p| color <- c} }
40+color c e = let p = e.props in
41+ { element=e.element, props={p| color <- Just c} }
4042tag name e = let p = e.props in
41− { element=e.element, props={p| tag <- JS.fromString name} }
43+ { element=e.element, props={p| tag <- JS.fromString name} }
4244link href e = let p = e.props in
43− { element=e.element, props={p| href <- JS.fromString href} }
45+ { element=e.element, props={p| href <- JS.fromString href} }
4446
4547emptyStr = JS.fromString ""
4648newElement w h e =
47− { props = Properties (guid ()) w h 1 NoFill emptyStr emptyStr, element = e }
49+ { props = Properties (guid ()) w h 1 Nothing emptyStr emptyStr, element = e }
4850
4951data ElementPrim
5052 = Image ImageStyle Int Int JSString
libraries/Graphics/LineStyle.elm+1−1
@@ -1,7 +1,7 @@
11
22module Graphics.LineStyle where
33
4−import Graphics.Color
4+import Graphics.Color as Color
55
66data LineCap = Butt | Round | Square
77data LineJoin = Soft | Sharp | Clip
libraries/List.elm+1
@@ -1,6 +1,7 @@
11
22module List where
33
4+import Native.Utils (min, max)
45import Native.List as L
56
67head : [a] -> a
libraries/Native/Date.js+2−2
@@ -27,8 +27,8 @@ Elm.Native.Date = function(elm) {
2727 hour : function(d) { return d.getHours(); },
2828 minute : function(d) { return d.getMinutes(); },
2929 second : function(d) { return d.getSeconds(); },
30− toTime : function(d) { return d.getTime(); }
31− dayOfWeek : function(d) { return { ctor:dayTable[d.getDay()] }; },
30+ toTime : function(d) { return d.getTime(); },
31+ dayOfWeek : function(d) { return { ctor:dayTable[d.getDay()] }; }
3232 };
3333
3434};
libraries/Native/Error.js+5−1
@@ -4,6 +4,8 @@ Elm.Native.Error = function(elm) {
44 elm.Native = elm.Native || {};
55 if (elm.Native.Error) return elm.Native.Error;
66
7+ var fromString = Elm.Native.JavaScript(elm).fromString;
8+
79 function Case(span) {
810 var msg = 'Non-exhaustive pattern match in case expression'
911 throw new Error(msg + " (" + span + ")")
@@ -14,5 +16,7 @@ Elm.Native.Error = function(elm) {
1416 throw new Error(msg + " (" + span + ")")
1517 }
1618
17− return elm.Native.Error = { Case: Case, If: If };
19+ function raise(str) { throw new Error(fromString(str)); }
20+
21+ return elm.Native.Error = { Case: Case, If: If, raise: raise };
1822};
libraries/Native/Graphics/Color.js+6−9
@@ -1,14 +1,12 @@
11
2−Elm.Native.Color = function(elm) {
2+
3+Elm.Native.Graphics.Color = function(elm) {
34 "use strict";
45
56 elm.Native = elm.Native || {};
6− if (elm.Native.Color) return elm.Native.Color;
7+ elm.Native.Graphics = elm.Native.Graphics || {};
8+ if (elm.Native.Graphics.Color) return elm.Native.Graphics.Color;
79
8− function extract(c) {
9− if (c._3 === 1) { return 'rgb(' + c._0 + ',' + c._1 + ',' + c._2 + ')'; }
10− return 'rgba(' + c._0 + ',' + c._1 + ',' + c._2 + ',' + c._3 + ')';
11− }
1210 function complement(rgb) {
1311 var hsv = toHSV(rgb);
1412 hsv.hue = (hsv.hue + 180) % 360;
@@ -59,11 +57,10 @@ Elm.Native.Color = function(elm) {
5957 return { ctor:"Color", _0:norm(r+m), _1:norm(g+m), _2:norm(b+m), _3:1 };
6058 }
6159
62− return elm.Native.Color = {
60+ return elm.Native.Graphics.Color = {
6361 hsva:F4(hsva),
6462 hsv:F3(hsv),
65− complement:complement,
66− extract:extract
63+ complement:complement
6764 };
6865
6966};
libraries/Native/List.js+1−1
@@ -5,7 +5,7 @@ Elm.Native.List = function(elm) {
55 elm.Native = elm.Native || {};
66 if (elm.Native.List) return elm.Native.List;
77
8− var Utils = elm.Native.Utils(elm);
8+ var Utils = Elm.Native.Utils(elm);
99
1010 var Nil = { ctor:'Nil' };
1111 function Cons(hd,tl) { return { ctor:"Cons", _0:hd, _1:tl }; }
libraries/Native/Prelude.jsnew file+7
@@ -0,0 +1,7 @@
1+
2+Elm.Prelude = function(elm) {
3+ 'use strict';
4+ if (elm.Prelude) return elm.Prelude;
5+
6+ return elm.Prelude = {};
7+};
libraries/Native/Show.js+3−2
@@ -2,6 +2,7 @@
22Elm.Native.Show = function(elm) {
33 'use strict';
44
5+ elm.Native = elm.Native || {};
56 if (elm.Native.Show) return elm.Native.Show;
67
78 var NList = Elm.Native.List(elm);
@@ -73,8 +74,8 @@ Elm.Native.Show = function(elm) {
7374 } else if (v.ctor === "Nil") {
7475 return "[]";
7576 } else if (v.ctor === "RBNode" || v.ctor === "RBEmpty") {
76− function cons(k){ return function(v) { return function(acc) { return NList.Cons(Tuple2(k,v),acc); }; }; }
77− var list = Dict.foldr(cons)(NList.Nil)(v);
77+ var cons = F3(function(k,v,acc){return NList.Cons(Tuple2(k,v),acc)});
78+ var list = A3(Dict.foldr, cons, NList.Nil, v);
7879 var name = "Dict";
7980 if (list.ctor === "Cons" && list._0._1.ctor === "Tuple0") {
8081 name = "Set";
libraries/Native/Signal/Signal.js+9−9
@@ -18,7 +18,7 @@ Elm.Native.Signal = function(elm) {
1818 }
1919
2020 function Input(base) {
21− this.id = Guid.guid();
21+ this.id = Utils.guid();
2222 this.value = base;
2323 this.kids = [];
2424 this.defaultNumberOfKids = 0;
@@ -28,11 +28,11 @@ Elm.Native.Signal = function(elm) {
2828 send(this, timestep, changed);
2929 return changed;
3030 };
31− Dispatcher.inputs.push(this);
31+ elm.inputs.push(this);
3232 }
3333
3434 function LiftN(update, args) {
35− this.id = Guid.guid();
35+ this.id = Utils.guid();
3636 this.value = update();
3737 this.kids = [];
3838
@@ -92,7 +92,7 @@ Elm.Native.Signal = function(elm) {
9292 }
9393
9494 function dropIf(pred,base,input) {
95− this.id = Guid.guid();
95+ this.id = Utils.guid();
9696 this.value = pred(input.value) ? base : input.value;
9797 this.kids = [];
9898 this.recv = function(timestep, changed, parentID) {
@@ -104,7 +104,7 @@ Elm.Native.Signal = function(elm) {
104104 }
105105
106106 function dropRepeats(input) {
107− this.id = Guid.guid();
107+ this.id = Utils.guid();
108108 this.value = input.value;
109109 this.kids = [];
110110 this.recv = function(timestep, changed, parentID) {
@@ -127,7 +127,7 @@ Elm.Native.Signal = function(elm) {
127127 }
128128
129129 function SampleOn(s1,s2) {
130− this.id = Guid.guid();
130+ this.id = Utils.guid();
131131 this.value = s2.value;
132132 this.kids = [];
133133
@@ -155,14 +155,14 @@ Elm.Native.Signal = function(elm) {
155155 var firstEvent = true;
156156 function update(v) {
157157 if (firstEvent) { firstEvent = false; return; }
158− setTimeout(function() { Dispatcher.notify(delayed.id, v) }, t);
158+ setTimeout(function() { elm.notify(delayed.id, v) }, t);
159159 }
160160 function first(a,b) { return a }
161161 return new SampleOn(delayed, lift2(F2(first), delayed, lift(update,s)));
162162 }
163163
164164 function Merge(s1,s2) {
165− this.id = Guid.guid();
165+ this.id = Utils.guid();
166166 this.value = s1.value;
167167 this.kids = [];
168168
@@ -223,7 +223,7 @@ Elm.Native.Signal = function(elm) {
223223 lift8 : F9(lift8),
224224 foldp : F3(foldp),
225225 delay : delay,
226− merge : F2(merge)
226+ merge : F2(merge),
227227 merges : merges,
228228 mergeEither : F2(mergeEither),
229229 average : F2(average),
libraries/Native/Utils.js+12−4
@@ -2,6 +2,9 @@
22Elm.Native.Utils = function(elm) {
33 'use strict';
44
5+ elm.Native = elm.Native || {};
6+ if (elm.Native.Utils) return elm.Native.Utils;
7+
58 function eq(x,y) {
69 if (x === y) return true;
710 if (typeof x === "object") {
@@ -50,8 +53,8 @@ Elm.Native.Utils = function(elm) {
5053 }
5154
5255
53− var Tuple0 = { ctor: "Tuple0" }
54− function Tuple2(x,y) { return { ctor = "Tuple2", _0:x, _1:y } }
56+ var Tuple0 = { ctor: "Tuple0" };
57+ function Tuple2(x,y) { return { ctor:"Tuple2", _0:x, _1:y } }
5558
5659 var count = 0;
5760 function guid(_) { return count++ }
@@ -77,7 +80,7 @@ Elm.Native.Utils = function(elm) {
7780 function replace(kvs,r) {
7881 var o = copy(r);
7982 for (var i = kvs.length; i--; ) {
80− kvsi = kvs[i];
83+ var kvsi = kvs[i];
8184 o[kvsi[0]] = kvsi[1];
8285 }
8386 return o;
@@ -90,6 +93,9 @@ Elm.Native.Utils = function(elm) {
9093 return o;
9194 }
9295
96+ function max(a,b) { return a > b ? a : b }
97+ function min(a,b) { return a < b ? a : b }
98+
9399 return elm.Native.Utils = {
94100 eq:eq,
95101 compare:compare,
@@ -99,6 +105,8 @@ Elm.Native.Utils = function(elm) {
99105 remove: remove,
100106 replace: replace,
101107 insert: insert,
102− guid: guid
108+ guid: guid,
109+ max : F2(max),
110+ min : F2(min)
103111 };
104112};
libraries/Prelude.elmdeleted−8
@@ -1,8 +0,0 @@
1−
2−module Prelude where
3−
4−import List
5−import Signal
6−
7−fst (x,y) = x
8−snd (x,y) = y
libraries/Signal.elm+1−3
@@ -1,9 +1,7 @@
11
22module Signal where
33
4−import Either
5−import Time
6−import Native.Signal
4+import Native.Signal as Native
75
86constant : a -> Signal a
97
libraries/Time.elm−2
@@ -3,8 +3,6 @@
33
44module Time where
55
6−import Native.Time
7−
86type Time = Float
97
108-- Units of time, making it easier to specify things like a
libraries/Touch.elm+1−1
@@ -3,7 +3,7 @@
33
44module Touch where
55
6−import Native.Touch
6+import Native.Touch as T
77
88type Touch = { x:Int, y:Int, id:Int, x0:Int, y0:Int, t0:Time }
99
libraries/WebSocket.elm+1−1
@@ -3,7 +3,7 @@
33
44module WebSocket where
55
6−import Native.WebSocket
6+import Native.WebSocket as WS
77
88-- Create a web-socket. The first argument is the URL of the desired
99-- web-socket server. The input signal holds the outgoing messages,
libraries/Window.elm−2
@@ -1,8 +1,6 @@
11
22module Window where
33
4−import Native.Window
5−
64-- The current dimensions of the window (i.e. the area viewable to the
75-- user, not including scroll bars).
86dimensions : Signal (Int,Int)
runtime/Init.js+2−3
@@ -22,7 +22,7 @@ Elm.init = function(module, baseNode) {
2222 var Render = ElmRuntime.Render;
2323 if (typeof baseNode === 'undefined') {
2424 baseNode = Render.newElement('div');
25− document.appendChild(baseNode);
25+ document.body.appendChild(baseNode);
2626 window.addEventListener('resize', function() {
2727 console.log('resize the base node');
2828 baseNode.style.width = document.documentElement.clientWidth + 'px';
@@ -35,11 +35,10 @@ Elm.init = function(module, baseNode) {
3535 "body { font-family: calibri, helvetica, arial, sans-serif; }";
3636 document.head.appendChild(style);
3737 }
38− baseNode.style.overflow = 'scroll';
3938
4039 // create the actuall RTS. Any impure modules will attach themselves to this
4140 // object. This permits many Elm programs to be embedded per document.
42− var elm = { notify: notify, node: baseNode, id: ElmRuntime.guid() };
41+ var elm = { notify: notify, node: baseNode, id: ElmRuntime.guid(), inputs: inputs };
4342
4443 // evaluate the given module and extract its 'main' value.
4544 signalGraph = module(elm).main;
runtime/Render.js+9−3
@@ -1,4 +1,5 @@
1−ElmRuntime = ElmRuntime || {};
1+
2+var ElmRuntime = ElmRuntime || {};
23ElmRuntime.Render = function() {
34'use strict';
45
@@ -20,12 +21,17 @@ function makeText(pos,txt) {
2021 return e;
2122}
2223
24+function extract(c) {
25+ if (c._3 === 1) { return 'rgb(' + c._0 + ',' + c._1 + ',' + c._2 + ')'; }
26+ return 'rgba(' + c._0 + ',' + c._1 + ',' + c._2 + ',' + c._3 + ')';
27+}
28+
2329function setProps(props, e) {
2430 e.style.width = (props.width |0) + 'px';
2531 e.style.height = (props.height|0) + 'px';
2632 if (props.opacity !== 1) { e.style.opacity = props.opacity; }
2733 if (props.color.ctor === 'Just') {
28− e.style.backgroundColor = Elm.Color.extract(props.color._0);
34+ e.style.backgroundColor = extract(props.color._0);
2935 }
3036 if (props.tag !== '') { e.id = props.tag; }
3137 if (props.href !== '') {
@@ -262,7 +268,7 @@ function update(node, curr, next) {
262268 e.style.opacity = props.opacity;
263269 }
264270 var nextColor = (props.color.ctor === 'Just' ?
265− Elm.Color.extract(props.color._0) : 'transparent');
271+ extract(props.color._0) : 'transparent');
266272 if (e.style.backgroundColor !== nextColor) e.style.backgroundColor = nextColor;
267273 if (props.tag !== currP.tag) { e.id = props.tag; }
268274 if (props.href !== currP.href) {