on master help sign in
Update first half of .elm libraries
8a700e8evancz
libraries/Automaton.elm−8
@@ -3,14 +3,6 @@ module Automaton where
3
3
4data Automaton a b = Automaton (a -> (b, Automaton a b))
4data Automaton a b = Automaton (a -> (b, Automaton a b))
5
5
6−{--- API possibilies: All names and types are up for debate!
7−(^>>) :: (a -> b) -> Automaton b c -> Automaton a c
8−(>>^) :: Automaton a b -> (b -> c) -> Automaton a c
9−(^<<) :: (b -> c) -> Automaton a b -> Automaton a c
10−(<<^) :: Automaton b c -> (a -> b) -> Automaton a c
11−--}
12−
13−
14run : Automaton a b -> Signal a -> Signal b
6run : Automaton a b -> Signal a -> Signal b
15run (Automaton m0) input =
7run (Automaton m0) input =
16 lift fst $ foldp' (\a (b, Automaton m) -> m a) m0 input
8 lift fst $ foldp' (\a (b, Automaton m) -> m a) m0 input
libraries/Date.elm+3−23
@@ -1,39 +1,19 @@
1
1
2module Date where
2module Date where
3
3
4−import Native.Date
5−
6data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
4data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
7
5
8data Month = Jan | Feb | Mar | Apr
6data Month = Jan | Feb | Mar | Apr
9 | May | Jun | Jul | Aug
7 | May | Jun | Jul | Aug
10 | Sep | Oct | Nov | Dec
8 | Sep | Oct | Nov | Dec
11
9
12−
13read : String -> Date
10read : String -> Date
14−read = Native.Date.read
15−
16toTime : Date -> Time
11toTime : Date -> Time
17−toTime = Native.Date.toTime
18−
19−
20−year : Date -> Int
21−year = Native.Date.year
22
12
13+year : Date -> Int
23month : Date -> Month
14month : Date -> Month
24−month = Native.Date.month
25−
26−day : Date -> Int
15+day : Date -> Int
27−day = Native.Date.day
28−
29dayOfWeek : Date -> Day
16dayOfWeek : Date -> Day
30−dayOfWeek = Native.Date.dayOfWeek
31−
32−hour : Date -> Int
17+hour : Date -> Int
33−hour = Native.Date.hour
34−
35minute : Date -> Int
18minute : Date -> Int
36−minute = Native.Date.minute
37−
38second : Date -> Int
19second : Date -> Int
39−second = Native.Date.second
libraries/Either.elm+7−3
@@ -1,4 +1,8 @@
1
1
2+module Either where
3+
4+import List (filter, partition)
5+
2data Either a b = Left a | Right b
6data Either a b = Left a | Right b
3
7
4either : (a -> c) -> (b -> c) -> Either a b -> c
8either : (a -> c) -> (b -> c) -> Either a b -> c
@@ -13,10 +17,10 @@ isRight e = case e of { Right _ -> True ; _ -> False }
13
17
14
18
15lefts : [Either a b] -> [a]
19lefts : [Either a b] -> [a]
16−lefts = Elm.List.filter isLeft
20+lefts = filter isLeft
17
21
18rights : [Either a b] -> [b]
22rights : [Either a b] -> [b]
19−rights = Elm.List.filter isRight
23+rights = filter isRight
20
24
21partition : [Either a b] -> ([a],[b])
25partition : [Either a b] -> ([a],[b])
22−partition = Elm.List.partition isLeft
26+partition = partition isLeft
libraries/HTTP.elm → libraries/Http.elmrenamed+4−5
@@ -2,9 +2,9 @@
2-- [WebSocket](http://elm-lang.org/docs/WebSocket.elm) library if
2-- [WebSocket](http://elm-lang.org/docs/WebSocket.elm) library if
3-- you have very strict latency requirements.
3-- you have very strict latency requirements.
4
4
5−module HTTP where
5+module Http where
6
6
7−import Native.HTTP
7+import Native.Http (send)
8
8
9-- The datatype for responses. Success contains only the returned message.
9-- The datatype for responses. Success contains only the returned message.
10-- Failures contain both an error code and an error message.
10-- Failures contain both an error code and an error message.
@@ -15,7 +15,7 @@ type Request a = {
15 url : String,
15 url : String,
16 body : a,
16 body : a,
17 headers : [(String,String)]
17 headers : [(String,String)]
18−}
18+ }
19
19
20-- Create a customized request. Arguments are request type (get, post, put,
20-- Create a customized request. Arguments are request type (get, post, put,
21-- delete, etc.), target url, data, and a list of additional headers.
21-- delete, etc.), target url, data, and a list of additional headers.
@@ -34,10 +34,9 @@ post url body = Request "POST" url body []
34-- Performs an HTTP request with the given requests. Produces a signal
34-- Performs an HTTP request with the given requests. Produces a signal
35-- that carries the responses.
35-- that carries the responses.
36send : Signal (Request a) -> Signal (Response String)
36send : Signal (Request a) -> Signal (Response String)
37−send = Native.HTTP.send
38
37
39-- Performs an HTTP GET request with the given urls. Produces a signal
38-- Performs an HTTP GET request with the given urls. Produces a signal
40-- that carries the responses.
39-- that carries the responses.
41sendGet : Signal String -> Signal (Response String)
40sendGet : Signal String -> Signal (Response String)
42−sendGet = send . lift get
41+sendGet reqs = send (lift get reqs)
43
42
libraries/JavaScript.elm+2−24
@@ -1,43 +1,21 @@
1
1
2module JavaScript where
2module JavaScript where
3
3
4−import Native.JavaScript as JS
5
4
6-- To Elm
5-- To Elm
7
6
8toString : JSString -> String
7toString : JSString -> String
9−toString = JS.toString
8+toList : JSArray a -> [a]
10−
11toInt : JSNumber -> Int
9toInt : JSNumber -> Int
12−toInt = JS.toInt
13−
14toFloat : JSNumber -> Float
10toFloat : JSNumber -> Float
15−toFloat = JS.id
16−
17toBool : JSBool -> Bool
11toBool : JSBool -> Bool
18−toBool = JS.id
19−
20−toList : JSArray a -> [a]
21−toList = JS.toList
22−
23−toRecord = JS.toRecord
24
12
25
13
26-- From Elm
14-- From Elm
27
15
28fromString : String -> JSString
16fromString : String -> JSString
29−fromString = JS.fromString
17+fromList : [a] -> JSArray a
30−
31fromInt : Int -> JSNumber
18fromInt : Int -> JSNumber
32−fromInt = JS.id
33−
34fromFloat : Float -> JSNumber
19fromFloat : Float -> JSNumber
35−fromFloat = JS.id
36−
37fromBool : Bool -> JSBool
20fromBool : Bool -> JSBool
38−fromBool = JS.id
39−
40−fromList : [a] -> JSArray a
41−fromList = JS.fromList
42
21
43−fromRecord = JS.fromRecord
libraries/Json.elm+22−23
@@ -30,47 +30,46 @@ fromString : String -> Maybe Value
30fromString s = Native.fromJSString (JS.fromString s)
30fromString s = Native.fromJSString (JS.fromString s)
31
31
32fromJSString : JSString -> Maybe Value
32fromJSString : JSString -> Maybe Value
33−fromJSString = Native.fromJSString
34
33
35
34
36-- Extract Elm values from Json values
35-- Extract Elm values from Json values
37
36
38−string : String -> Value -> String
37+string : Value -> String
39−string base v = case v of { String s -> s ; _ -> base }
38+string v = case v of { String s -> s ; _ -> "" }
40
39
41−number : Float -> Value -> Float
40+number : Value -> Float
42−number base v = case v of { Number n -> n ; _ -> base }
41+number v = case v of { Number n -> n ; _ -> 0 }
43
42
44−boolean : Bool -> Value -> Bool
43+boolean : Value -> Bool
45−boolean base v = case v of { Boolean b -> b ; _ -> base }
44+boolean v = case v of { Boolean b -> b ; _ -> False }
46
45
47−array : [Value] -> Value -> [Value]
46+array : Value -> [Value]
48−array base v = case v of { Array a -> a ; _ -> base }
47+array v = case v of { Array a -> a ; _ -> [] }
49
48
50−object : Dict String Value -> Value -> Dict String Value
49+object : Value -> Dict String Value
51−object base v = case v of { Object o -> o ; _ -> base }
50+object v = case v of { Object o -> o ; _ -> Dict.empty }
52
51
53
52
54-- Extract Elm values from dictionaries of Json values
53-- Extract Elm values from dictionaries of Json values
55
54
56−find get =
55+find get base =
57− let f base key dict =
56+ let f key dict =
58 case Dict.lookup key dict of
57 case Dict.lookup key dict of
59 Nothing -> base
58 Nothing -> base
60− Just v -> get base v
59+ Just v -> get v
61 in f
60 in f
62
61
63findString : String -> Dict String Value -> String
62findString : String -> Dict String Value -> String
64−findString = find string
63+findString = find string ""
65
64
66−findNumber : Float -> Dict String Value -> Float
65+findNumber : String -> Dict String Value -> Float
67−findNumber = find number
66+findNumber = find number 0
68
67
69−findBoolean : Bool -> Dict String Value -> Bool
68+findBoolean : String -> Dict String Value -> Bool
70−findBoolean = find boolean
69+findBoolean = find boolean False
71
70
72−findArray : [Value] -> Dict String Value -> [Value]
71+findArray : String -> Dict String Value -> [Value]
73−findArray = find array
72+findArray = find array []
74
73
75−findObject : Dict String Value -> Dict String Value -> Dict String Value
74+findObject : String -> Dict String Value -> Dict String Value
76−findObject = find object
75+findObject = find object Dict.empty
libraries/Native/JavaScript.js+7−1
@@ -61,13 +61,19 @@ Elm.Native.JavaScript = function(elm) {
61 throw new Error("'fromRecord' must be called on a record.");
61 throw new Error("'fromRecord' must be called on a record.");
62 }
62 }
63
63
64+ function id(n) { return n }
65+
64 return elm.Native.JavaScript = {
66 return elm.Native.JavaScript = {
65− id : function(n) { return n },
67+ toFloat : id,
68+ toBool : id,
66 toInt : function(n) { return n|0 },
69 toInt : function(n) { return n|0 },
67 toString : function(s) { return List.fromArray(s) },
70 toString : function(s) { return List.fromArray(s) },
68 toList : List.fromArray,
71 toList : List.fromArray,
69 fromString : function(s) { return List.toArray(s).join('') },
72 fromString : function(s) { return List.toArray(s).join('') },
70 fromList : List.toArray,
73 fromList : List.toArray,
74+ fromInt : id,
75+ fromFloat : id,
76+ fromBool : id,
71 toRecord : fromJS,
77 toRecord : fromJS,
72 fromRecord : fromRecord
78 fromRecord : fromRecord
73 };
79 };