on master help sign in
Convert Date, Mouse, Window, and Signal docs.
6869015Max Goldstein
libraries/Date.elm+32−24
@@ -1,9 +1,17 @@
1
1
2−-- Library for working with dates. It is still a work in progress, so email
3−-- the mailing list if you are having issues with internationalization or
4−-- locale formatting or something.
5module Date where
2module Date where
6
3
4+{-| Library for working with dates. Email the mailing list if you encounter
5+issues with internationalization or locale formatting.
6+
7+# Conversions
8+@docs read, toTime
9+
10+# Extractions
11+@docs year, month, Month, day, dayOfWeek, Day, hour, minute, second
12+
13+-}
14+
7import Basics (String)
15import Basics (String)
8import Native.Date
16import Native.Date
9import Time (Time)
17import Time (Time)
@@ -11,55 +19,55 @@ import Maybe (Maybe)
11
19
12data Date = Date
20data Date = Date
13
21
14−-- Represents the days of the week.
22+{-| Represents the days of the week. -}
15data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
23data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
16
24
17−-- Represents the month of the year.
25+{-| Represents the month of the year. -}
18data Month = Jan | Feb | Mar | Apr
26data Month = Jan | Feb | Mar | Apr
19 | May | Jun | Jul | Aug
27 | May | Jun | Jul | Aug
20 | Sep | Oct | Nov | Dec
28 | Sep | Oct | Nov | Dec
21
29
22−-- Attempt to read a date from a string.
30+{-| Attempt to read a date from a string. -}
23read : String -> Maybe Date
31read : String -> Maybe Date
24read = Native.Date.read
32read = Native.Date.read
25
33
26−-- Convert a date into a time since midnight (UTC) of 1 January 1990 (i.e.
34+{-| Convert a date into a time since midnight (UTC) of 1 January 1990 (i.e.
27−-- [UNIX time](http://en.wikipedia.org/wiki/Unix_time)). Given the date 23 June
35+[UNIX time](http://en.wikipedia.org/wiki/Unix_time)). Given the date 23 June
28−-- 1990 at 11:45AM this returns the corresponding time.
36+1990 at 11:45AM this returns the corresponding time. -}
29toTime : Date -> Time
37toTime : Date -> Time
30toTime = Native.Date.toTime
38toTime = Native.Date.toTime
31
39
32−-- Extract the year of a given date. Given the date 23 June 1990 at 11:45AM
40+{-| Extract the year of a given date. Given the date 23 June 1990 at 11:45AM
33−-- this returns the integer `1990`.
41+this returns the integer `1990`. -}
34year : Date -> Int
42year : Date -> Int
35year = Native.Date.year
43year = Native.Date.year
36
44
37−-- Extract the month of a given date. Given the date 23 June 1990 at 11:45AM
45+{-| Extract the month of a given date. Given the date 23 June 1990 at 11:45AM
38−-- this returns the Month `Jun` as defined below.
46+this returns the Month `Jun` as defined below. -}
39month : Date -> Month
47month : Date -> Month
40month = Native.Date.month
48month = Native.Date.month
41
49
42−-- Extract the day of a given date. Given the date 23 June 1990 at 11:45AM
50+{-| Extract the day of a given date. Given the date 23 June 1990 at 11:45AM
43−-- this returns the integer `23`.
51+this returns the integer `23`. -}
44day : Date -> Int
52day : Date -> Int
45day = Native.Date.day
53day = Native.Date.day
46
54
47−-- Extract the day of the week for a given date. Given the date 23 June
55+{-| Extract the day of the week for a given date. Given the date 23 June
48−-- 1990 at 11:45AM this returns the Day `Thu` as defined below.
56+1990 at 11:45AM this returns the Day `Thu` as defined below. -}
49dayOfWeek : Date -> Day
57dayOfWeek : Date -> Day
50dayOfWeek = Native.Date.dayOfWeek
58dayOfWeek = Native.Date.dayOfWeek
51
59
52−-- Extract the hour of a given date. Given the date 23 June 1990 at 11:45AM
60+{-| Extract the hour of a given date. Given the date 23 June 1990 at 11:45AM
53−-- this returns the integer `11`.
61+this returns the integer `11`. -}
54hour : Date -> Int
62hour : Date -> Int
55hour = Native.Date.hour
63hour = Native.Date.hour
56
64
57−-- Extract the minute of a given date. Given the date 23 June 1990 at 11:45AM
65+{-| Extract the minute of a given date. Given the date 23 June 1990 at 11:45AM
58−-- this returns the integer `45`.
66+this returns the integer `45`. -}
59minute : Date -> Int
67minute : Date -> Int
60minute = Native.Date.minute
68minute = Native.Date.minute
61
69
62−-- Extract the second of a given date. Given the date 23 June 1990 at 11:45AM
70+{-| Extract the second of a given date. Given the date 23 June 1990 at 11:45AM
63−-- this returns the integer `0`.
71+this returns the integer `0`. -}
64second : Date -> Int
72second : Date -> Int
65−second = Native.Date.second
73+second = Native.Date.second
libraries/Mouse.elm+19−9
@@ -1,31 +1,41 @@
1
1
2module Mouse where
2module Mouse where
3
3
4+{-| Library for working with mouse input.
5+
6+# Position
7+@docs position, x, y
8+
9+# Button Status
10+@docs isDown, clicks, isClicked
11+
12+-}
13+
4import Signal (Signal)
14import Signal (Signal)
5import Native.Mouse
15import Native.Mouse
6
16
7−-- The current mouse position.
17+{-| The current mouse position. -}
8position : Signal (Int,Int)
18position : Signal (Int,Int)
9position = Native.Mouse.position
19position = Native.Mouse.position
10
20
11−-- The current x-coordinate of the mouse.
21+{-| The current x-coordinate of the mouse. -}
12x : Signal Int
22x : Signal Int
13x = Native.Mouse.x
23x = Native.Mouse.x
14
24
15−-- The current y-coordinate of the mouse.
25+{-| The current y-coordinate of the mouse. -}
16y : Signal Int
26y : Signal Int
17y = Native.Mouse.y
27y = Native.Mouse.y
18
28
19−-- The current state of the left mouse-button.
29+{-| The current state of the left mouse-button.
20−-- True when the button is down, and false otherwise.
30+True when the button is down, and false otherwise. -}
21isDown : Signal Bool
31isDown : Signal Bool
22isDown = Native.Mouse.isDown
32isDown = Native.Mouse.isDown
23
33
24−-- True immediately after the left mouse-button has been clicked,
34+{-| True immediately after the left mouse-button has been clicked,
25−-- and false otherwise.
35+and false otherwise. -}
26isClicked : Signal Bool
36isClicked : Signal Bool
27isClicked = Native.Mouse.isClicked
37isClicked = Native.Mouse.isClicked
28
38
29−-- Always equal to unit. Event triggers on every mouse click.
39+{-| Always equal to unit. Event triggers on every mouse click. -}
30clicks : Signal ()
40clicks : Signal ()
31−clicks = Native.Mouse.clicks
41+clicks = Native.Mouse.clicks
libraries/Signal.elm+82−58
@@ -1,32 +1,52 @@
1
1
2−-- The library for general signal manipulation. Some useful functions for
2+{-| The library for general signal manipulation. Includes lift functions up to
3+`lift8` and infix lift operators `<~` and `~`, combinations, filters, and
4+past-dependence.
5+
6+Signals are time-varying values. Lifted functions are reevaluated whenver any of
7+their input signals has an event. Signal events may be of the same value as the
8+previous value of the signal. Such signals are useful for timing and
9+past-dependence.
10+
3−-- working with time (e.g. setting FPS) and combining signals and time (e.g.
11+Some useful functions for working with time (e.g. setting FPS) and combining
4−-- delaying updates, getting timestamps) can be found in the
12+signals and time (e.g. delaying updates, getting timestamps) can be found in
5−-- [`Time`](/docs/Signal/Time.elm) library.
13+the [`Time`](/docs/Signal/Time.elm) library.
6−--
14+
7−-- Note: There are lift functions up to `lift8`.
15+# Combine
16+@docs constant, lift, lift2, merge, merges, combine
17+
18+# Pretty Lift
19+@docs (<~), (~)
20+
21+# Past-Dependence
22+@docs foldp, count, countIf
23+
24+#Filters
25+@docs keepIf, dropIf, keepWhen, dropWhen, dropRepeats, sampleOn
26+
27+# Do you even lift?
28+@docs lift3, lift4, lift5, lift6, lift7, lift8
29+
30+-}
8module Signal where
31module Signal where
9
32
10import Native.Signal
33import Native.Signal
11import List (foldr)
34import List (foldr)
12
35
13data Signal a = Signal
36data Signal a = Signal
14−-- = Constant a
15−-- | Lift (a -> a) (Signal a)
16
37
17−-- Create a constant signal that never changes.
38+{-| Create a constant signal that never changes. -}
18constant : a -> Signal a
39constant : a -> Signal a
19constant = Native.Signal.constant
40constant = Native.Signal.constant
20
41
21−-- Transform a signal with a given function.
42+{-| Transform a signal with a given function. -}
22lift : (a -> b) -> Signal a -> Signal b
43lift : (a -> b) -> Signal a -> Signal b
23lift = Native.Signal.lift
44lift = Native.Signal.lift
24
45
25−-- Combine two signals with a given function.
46+{-| Combine two signals with a given function. -}
26lift2 : (a -> b -> c) -> Signal a -> Signal b -> Signal c
47lift2 : (a -> b -> c) -> Signal a -> Signal b -> Signal c
27lift2 = Native.Signal.lift2
48lift2 = Native.Signal.lift2
28
49
29−-- Combine three signals with a given function.
30lift3 : (a -> b -> c -> d) -> Signal a -> Signal b -> Signal c -> Signal d
50lift3 : (a -> b -> c -> d) -> Signal a -> Signal b -> Signal c -> Signal d
31lift3 = Native.Signal.lift3
51lift3 = Native.Signal.lift3
32
52
@@ -49,25 +69,25 @@ lift8 : (a -> b -> c -> d -> e -> f -> g -> h -> i)
49lift8 = Native.Signal.lift8
69lift8 = Native.Signal.lift8
50
70
51
71
52−-- Create a past-dependent signal. Each value given on the input signal will
72+{-| Create a past-dependent signal. Each value given on the input signal will
53−-- be accumulated, producing a new output value.
73+be accumulated, producing a new output value.
54−--
74+
55−-- For instance, `(foldp (\\arrows number -> number + arrows.y) 0 Keyboard.arrows)`
75+For instance, `foldp (+) 0 (fps 40)` is the time the program has been running,
56−-- increments or decrements the accumulated value (which starts at zero) when the up or down arrow keys are pressed.
76+updated 40 times a second. -}
57foldp : (a -> b -> b) -> b -> Signal a -> Signal b
77foldp : (a -> b -> b) -> b -> Signal a -> Signal b
58foldp = Native.Signal.foldp
78foldp = Native.Signal.foldp
59
79
60−-- Merge two signals into one, biased towards the first signal if both signals
80+{-| Merge two signals into one, biased towards the first signal if both signals
61−-- update at the same time.
81+update at the same time. -}
62merge : Signal a -> Signal a -> Signal a
82merge : Signal a -> Signal a -> Signal a
63merge = Native.Signal.merge
83merge = Native.Signal.merge
64
84
65−-- Merge many signals into one, biased towards the left-most signal if multiple
85+{-| Merge many signals into one, biased towards the left-most signal if multiple
66−-- signals update simultaneously.
86+signals update simultaneously. -}
67merges : [Signal a] -> Signal a
87merges : [Signal a] -> Signal a
68merges = Native.Signal.merges
88merges = Native.Signal.merges
69
89
70−-- Combine a list of signals into a signal of lists.
90+{-| Combine a list of signals into a signal of lists. -}
71combine : [Signal a] -> Signal [a]
91combine : [Signal a] -> Signal [a]
72combine = foldr (Native.Signal.lift2 (::)) (Native.Signal.constant [])
92combine = foldr (Native.Signal.lift2 (::)) (Native.Signal.constant [])
73
93
@@ -76,70 +96,74 @@ combine = foldr (Native.Signal.lift2 (::)) (Native.Signal.constant [])
76 -- fold over non-homogeneous inputs.
96 -- fold over non-homogeneous inputs.
77 -- mergeEither : Signal a -> Signal b -> Signal (Either a b)
97 -- mergeEither : Signal a -> Signal b -> Signal (Either a b)
78
98
79−-- Count the number of events that have occured.
99+{-| Count the number of events that have occured. -}
80count : Signal a -> Signal Int
100count : Signal a -> Signal Int
81count = Native.Signal.count
101count = Native.Signal.count
82
102
83−-- Count the number of events that have occured that satisfy a given predicate.
103+{-| Count the number of events that have occured that satisfy a given predicate.
104+-}
84countIf : (a -> Bool) -> Signal a -> Signal Int
105countIf : (a -> Bool) -> Signal a -> Signal Int
85countIf = Native.Signal.countIf
106countIf = Native.Signal.countIf
86
107
87−-- Keep only events that satisfy the given predicate. Elm does not allow
108+{-| Keep only events that satisfy the given predicate. Elm does not allow
88−-- undefined signals, so a base case must be provided in case the predicate is
109+undefined signals, so a base case must be provided in case the predicate is
89−-- never satisfied.
110+never satisfied. -}
90keepIf : (a -> Bool) -> a -> Signal a -> Signal a
111keepIf : (a -> Bool) -> a -> Signal a -> Signal a
91keepIf = Native.Signal.keepIf
112keepIf = Native.Signal.keepIf
92
113
93−-- Drop events that satisfy the given predicate. Elm does not allow undefined
114+{-| Drop events that satisfy the given predicate. Elm does not allow undefined
94−-- signals, so a base case must be provided in case the predicate is never
115+signals, so a base case must be provided in case the predicate is never
95−-- satisfied.
116+satisfied. -}
96dropIf : (a -> Bool) -> a -> Signal a -> Signal a
117dropIf : (a -> Bool) -> a -> Signal a -> Signal a
97dropIf = Native.Signal.dropIf
118dropIf = Native.Signal.dropIf
98
119
99−-- Keep events only when the first signal is true. When the first signal becomes
120+{-| Keep events only when the first signal is true. When the first signal
100−-- true, the most recent value of the second signal will be propagated. Until
121+becomes true, the most recent value of the second signal will be propagated.
101−-- the first signal becomes false again, all events will be propagated. Elm does
122+Until the first signal becomes false again, all events will be propagated. Elm
102−-- not allow undefined signals, so a base case must be provided in case the first
123+does not allow undefined signals, so a base case must be provided in case the
103−-- signal is never true.
124+first signal is never true. -}
104keepWhen : Signal Bool -> a -> Signal a -> Signal a
125keepWhen : Signal Bool -> a -> Signal a -> Signal a
105keepWhen = Native.Signal.keepWhen
126keepWhen = Native.Signal.keepWhen
106
127
107−-- Drop events when the first signal is true. When the first signal becomes false,
128+{-| Drop events when the first signal is true. When the first signal becomes
108−-- the most recent value of the second signal will be propagated. Until the first
129+false, the most recent value of the second signal will be propagated. Until the
109−-- signal becomes true again, all events will be propagated. Elm does not allow
130+first signal becomes true again, all events will be propagated. Elm does not
110−-- undefined signals, so a base case must be provided in case the first signal is
131+allow undefined signals, so a base case must be provided in case the first
111−-- always true.
132+signal is always true. -}
112dropWhen : Signal Bool -> a -> Signal a -> Signal a
133dropWhen : Signal Bool -> a -> Signal a -> Signal a
113dropWhen = Native.Signal.dropWhen
134dropWhen = Native.Signal.dropWhen
114
135
115−-- Drop sequential repeated values. For example, if a signal produces the
136+{-| Drop sequential repeated values. For example, if a signal produces the
116−-- sequence `[1,1,2,2,1]`, it becomes `[1,2,1]` by dropping the values that
137+sequence `[1,1,2,2,1]`, it becomes `[1,2,1]` by dropping the values that are the
117−-- are the same as the previous value.
138+same as the previous value. -}
118dropRepeats : Signal a -> Signal a
139dropRepeats : Signal a -> Signal a
119dropRepeats = Native.Signal.dropRepeats
140dropRepeats = Native.Signal.dropRepeats
120
141
121−-- Sample from the second input every time an event occurs on the first input.
142+{-| Sample from the second input every time an event occurs on the first input.
122−-- For example, `(sampleOn clicks (every second))` will give the approximate
143+For example, `(sampleOn clicks (every second))` will give the approximate time
123−-- time of the latest click.
144+of the latest click. -}
124sampleOn : Signal a -> Signal b -> Signal b
145sampleOn : Signal a -> Signal b -> Signal b
125sampleOn = Native.Signal.sampleOn
146sampleOn = Native.Signal.sampleOn
126
147
127−-- An alias for `lift`. A prettier way to apply a
148+{-| An alias for `lift`. A prettier way to apply a function to the current value
128−-- function to the current value of a signal.
149+of a signal. -}
129−--
130−-- lift f signal == f <~ signal
131(<~) : (a -> b) -> Signal a -> Signal b
150(<~) : (a -> b) -> Signal a -> Signal b
132f <~ s = Native.Signal.lift f s
151f <~ s = Native.Signal.lift f s
133
152
153+{-| Informally, an alias for `liftN`. Intersperse it between additional signal
154+arguments of the lifted function.
155+
134−-- Signal application. This takes two signals, holding a function and
156+Formally, signal application. This takes two signals, holding a function and
135−-- a value. It applies the current function to the current value.
157+a value. It applies the current function to the current value.
136−--
158+
137−-- So the following expressions are equivalent:
159+The following expressions are equivalent:
138−--
160+
139−-- scene <~ Window.dimensions ~ Mouse.position
161+ scene <~ Window.dimensions ~ Mouse.position
140−-- lift2 scene Window.dimensions Mouse.position
162+ lift2 scene Window.dimensions Mouse.position
163+-}
164+
141(~) : Signal (a -> b) -> Signal a -> Signal b
165(~) : Signal (a -> b) -> Signal a -> Signal b
142sf ~ s = Native.Signal.lift2 (\f x -> f x) sf s
166sf ~ s = Native.Signal.lift2 (\f x -> f x) sf s
143
167
144infixl 4 <~
168infixl 4 <~
145−infixl 4 ~
169+infixl 4 ~
libraries/Window.elm+13−4
@@ -1,18 +1,27 @@
1
1
2module Window where
2module Window where
3
3
4+{-| Provides information about the container that your Elm program lives in.
5+When you embed Elm in a `<div>` it gives the dimensions of the container, not
6+the whole window.
7+
8+# Dimensions
9+@docs dimensions, width, height
10+
11+-}
12+
4import Signal (Signal)
13import Signal (Signal)
5import Native.Window
14import Native.Window
6
15
7−-- The current dimensions of the window (i.e. the area viewable to the
16+{-| The current width and height of the window (i.e. the area viewable to the
8−-- user, not including scroll bars).
17+user, not including scroll bars). -}
9dimensions : Signal (Int,Int)
18dimensions : Signal (Int,Int)
10dimensions = Native.Window.dimensions
19dimensions = Native.Window.dimensions
11
20
12−-- The current width of the window.
21+{-| The current width of the window. -}
13width : Signal Int
22width : Signal Int
14width = Native.Window.width
23width = Native.Window.width
15
24
16−-- The current height of the window.
25+{-| The current height of the window. -}
17height : Signal Int
26height : Signal Int
18height = Native.Window.height
27height = Native.Window.height