Skip to content

Commit

Permalink
Get more libraries compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
process-bot committed Jul 26, 2013
1 parent 602117f commit 20067c4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
3 changes: 2 additions & 1 deletion libraries/Date.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
module Date where

import Native.Date as Native
import Time
import Time (Time)
import Maybe (Maybe)

data Date = Date

Expand Down
3 changes: 2 additions & 1 deletion libraries/Http.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Http where

import Native.Http (send)
import Native.Http as Native
import Signal (lift)

-- The datatype for responses. Success contains only the returned message.
Expand Down Expand Up @@ -35,6 +35,7 @@ post url body = Request "POST" url body []
-- Performs an HTTP request with the given requests. Produces a signal
-- that carries the responses.
send : Signal (Request a) -> Signal (Response String)
send = Native.send

-- Performs an HTTP GET request with the given urls. Produces a signal
-- that carries the responses.
Expand Down
29 changes: 15 additions & 14 deletions libraries/Set.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,61 @@ module Set (empty,singleton,insert,remove
,toList,fromList
) where

import Maybe (Maybe)
import Dict as Dict
import List as List

type Set t = Dict t ()
type Set t = Dict.Dict t ()

-- Create an empty set.
empty : Set (Comparable k)
empty : Set comparable
empty = Dict.empty

-- Create a set with one value.
singleton : Comparable k -> Set (Comparable k)
singleton : comparable -> Set comparable
singleton k = Dict.singleton k ()

-- Insert a value into a set.
insert : Comparable k -> Set (Comparable k) -> Set (Comparable k)
insert : comparable -> Set comparable -> Set comparable
insert k = Dict.insert k ()

-- Remove a value from a set. If the value is not found, no changes are made.
remove : Comparable k -> Set (Comparable k) -> Set (Comparable k)
remove : comparable -> Set comparable -> Set comparable
remove = Dict.remove

-- Determine if a value is in a set.
member : Comparable k -> Set (Comparable k) -> Bool
member : comparable -> Set comparable -> Bool
member = Dict.member

-- Get the union of two sets. Keep all values.
union : Set (Comparable k) -> Set (Comparable k) -> Set (Comparable k)
union : Set comparable -> Set comparable -> Set comparable
union = Dict.union

-- Get the intersection of two sets. Keeps values that appear in both sets.
intersect : Set (Comparable k) -> Set (Comparable k) -> Set (Comparable k)
intersect : Set comparable -> Set comparable -> Set comparable
intersect = Dict.intersect

-- Get the difference between the first set and the second. Keeps values
-- that do not appear in the second set.
diff : Set (Comparable k) -> Set (Comparable k) -> Set (Comparable k)
diff : Set comparable -> Set comparable -> Set comparable
diff = Dict.diff

-- Convert a set into a list.
toList : Set (Comparable k) -> [Comparable k]
toList : Set comparable -> [comparable]
toList = Dict.keys

-- Convert a list into a set, removing any duplicates.
fromList : [Comparable k] -> Set (Comparable k)
fromList : [comparable] -> Set comparable
fromList xs = List.foldl insert empty xs

-- Fold over the values in a set, in order from lowest to highest.
foldl : (Comparable a -> b -> b) -> b -> Set (Comparable a) -> b
foldl : (comparable -> b -> b) -> b -> Set comparable -> b
foldl f b s = Dict.foldl (\k _ b -> f k b) b s

-- Fold over the values in a set, in order from highest to lowest.
foldr : (Comparable a -> b -> b) -> b -> Set (Comparable a) -> b
foldr : (comparable -> b -> b) -> b -> Set comparable -> b
foldr f b s = Dict.foldr (\k _ b -> f k b) b s

-- Map a function onto a set, creating a new set with no duplicates.
map : (Comparable a -> Comparable b) -> Set (Comparable a) -> Set (Comparable b)
map : (comparable -> comparable') -> Set comparable -> Set comparable'
map f s = fromList (List.map f (toList s))
5 changes: 4 additions & 1 deletion libraries/Touch.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
-- include gestures that would be useful for both games and web-pages.
module Touch where

import Native.Touch as T
import Native.Touch as Native
import Time (Time)

-- Every `Touch` has `xy` coordinates. It also has an identifier `id` to
-- distinguish one touch from another.
Expand All @@ -14,7 +15,9 @@ type Touch = { x:Int, y:Int, id:Int, x0:Int, y0:Int, t0:Time }

-- A list of ongoing touches.
touches : Signal [Touch]
touches = Native.touches

-- The last position that was tapped. Default value is `{x=0,y=0}`.
-- Updates whenever the user taps the screen.
taps : Signal { x:Int, y:Int }
taps = Native.taps
3 changes: 2 additions & 1 deletion libraries/WebSocket.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
-- standard requests like GET, POST, etc.
module WebSocket where

import Native.WebSocket as WS
import Native.WebSocket as Native

-- Create a web-socket. The first argument is the URL of the desired
-- web-socket server. The input signal holds the outgoing messages,
-- and the resulting signal contains the incoming ones.
connect : String -> Signal String -> Signal String
connect = Native.connect

-- data Action = Open String | Close String | Send String String
-- connections : Signal Action -> Signal String

0 comments on commit 20067c4

Please sign in to comment.