on master help sign in
Change the style of some documentation, experimenting with styles for elm-doc
commitc4d07300a11f2b61510ceaf894e8bd4f8bdf7409 authorEvan Czaplicki <info@elm-lang.org> dateMon 2 Sep 2013, 19:28 (13 years ago) parente2d2c45
2 files changed+224−140
libraries/Graphics/Input.elm+118−76 libraries/List.elm+106−64
libraries/Graphics/Input.elm+118−76
@@ -1,4 +1,3 @@
1−
21module Graphics.Input where
32
43import Basics (String)
@@ -9,118 +8,158 @@ import Graphics.Element (Element)
98import Maybe (Maybe)
109import JavaScript (JSString)
1110
11+{-| DOCUMENT STRUCTURE
12+
13+This module is for creating standard input widgets such as buttons and
14+text boxes. In general, functions in this library return a signal representing
15+events from the user.
16+
17+The simplest inputs are *one-way inputs*, meaning the user can update
18+them, but the programmer cannot. If you need to update an input from
19+within the program you want the slightly more complex *two-way inputs*.
20+This document will always show the one-way inputs first, *then* the
21+two-way inputs.
22+
23+# Buttons
24+@docs button, customButton, buttons, customButtons
25+
26+# Fields
27+@docs field, password, email, fields, FieldState, emptyFieldState
28+
29+# Checkboxes
30+@docs checkbox, checkboxes
31+
32+# Drop Downs
33+@docs stringDropDown, dropDown
34+
35+# Mouse Hover
36+@docs hoverable, hoverables
37+
38+-}
39+
1240id x = x
1341
14−-- Create a group of buttons.
15−--
16−-- * The first argument is the default value of the `events` signal.
17−-- * The `events` signal represents all of the activity in this group
18−-- of buttons.
19−-- * The `button` function creates a button
20−-- with the given name, like &ldquo;Submit&rdquo; or &ldquo;Cancel&rdquo;.
21−-- The `a` value is sent to `events` whenever the button is pressed.
42+{-| Create a group of buttons.
43+
44+ * The first argument is the default value of the `events` signal.
45+ * The `events` signal represents all of the activity in this group
46+ of buttons.
47+ * The `button` function creates a button
48+ with the given name, like &ldquo;Submit&rdquo; or &ldquo;Cancel&rdquo;.
49+ The `a` value is sent to `events` whenever the button is pressed.
50+-}
2251buttons : a -> { events : Signal a,
2352 button : a -> String -> Element }
2453buttons = Native.Graphics.Input.buttons
2554
26−-- Create a button with a given label. The result is an `Element` and
27−-- a signal of units. This signal triggers whenever the button is pressed.
55+{-| Create a button with a given label. The result is an `Element` and
56+a signal of units. This signal triggers whenever the button is pressed.
57+-}
2858button : String -> (Element, Signal ())
2959button txt =
3060 let pool = buttons ()
3161 in (pool.button () txt, pool.events)
3262
33−-- Create a group of custom buttons.
34−--
35−-- * The first argument is the default value of the `events` signal.
36−-- * The `events` signal represents all of the activity in this group
37−-- of custom buttons.
38−-- * The `customButton` function creates a button with three different visual
39−-- states, one for up, hovering, and down. The resulting button has dimensions
40−-- large enough to fit all three possible `Elements`.
41−-- The `a` value is sent to `events` whenever the button is pressed.
63+{-| Create a group of custom buttons.
64+
65+ * The first argument is the default value of the `events` signal.
66+ * The `events` signal represents all of the activity in this group
67+ of custom buttons.
68+ * The `customButton` function creates a button with three different visual
69+ states, one for up, hovering, and down. The resulting button has dimensions
70+ large enough to fit all three possible `Elements`.
71+ The `a` value is sent to `events` whenever the button is pressed.
72+-}
4273customButtons : a -> { events : Signal a,
4374 customButton : a -> Element -> Element -> Element -> Element }
4475customButtons = Native.Graphics.Input.customButtons
4576
46−-- Create a button with custom states for up, hovering, and down
47−-- (given in that order). The result is an `Element` and
48−-- a signal of units. This signal triggers whenever the button is pressed.
77+{-| Create a button with custom states for up, hovering, and down
78+(given in that order). The result is an `Element` and a signal of
79+units. This signal triggers whenever the button is pressed.
80+-}
4981customButton : Element -> Element -> Element -> (Element, Signal ())
5082customButton up hover down =
5183 let pool = customButtons ()
5284 in (pool.customButton () up hover down, pool.events)
5385
54−-- Create a group of checkboxes.
55−--
56−-- * The first argument is the default value of the `events` signal.
57−-- * The `events` signal represents all of the activity in this group
58−-- of checkboxes.
59−-- * The `checkbox` function creates a
60−-- checkbox with a given state. The `(Bool -> a)` function is used
61−-- when the checkbox is modified. It takes the new state and turns
62−-- it into a value that can be sent to `events`. For example, this
63−-- lets you add an ID to distinguish between checkboxes.
86+{-| Create a group of checkboxes.
87+
88+ * The first argument is the default value of the `events` signal.
89+ * The `events` signal represents all of the activity in this group
90+ of checkboxes.
91+ * The `checkbox` function creates a
92+ checkbox with a given state. The `(Bool -> a)` function is used
93+ when the checkbox is modified. It takes the new state and turns
94+ it into a value that can be sent to `events`. For example, this
95+ lets you add an ID to distinguish between checkboxes.
96+-}
6497checkboxes : a -> { events : Signal a,
6598 checkbox : (Bool -> a) -> Bool -> Element }
6699checkboxes = Native.Graphics.Input.checkboxes
67100
68−-- Create a checkbox with a given start state. Unlike `button`, this result
69−-- is a *signal* of elements. That is because a checkbox has state that
70−-- updates based on user input.
71−-- The boolean signal represents the current state of the checkbox.
101+{-| Create a checkbox with a given start state. Unlike `button`, this
102+result is a *signal* of elements. That is because a checkbox has state
103+that updates based on user input. The boolean signal represents the
104+current state of the checkbox.
105+-}
72106checkbox : Bool -> (Signal Element, Signal Bool)
73107checkbox b =
74108 let cbs = checkboxes b
75109 in (lift (cbs.checkbox id) cbs.events, cbs.events)
76110
77−-- Detect when the mouse is hovering over some elements. This
78−-- allows you to create and destroy elements dynamically and still
79−-- detect hover information.
111+{-| Detect when the mouse is hovering over some elements. This
112+allows you to create and destroy elements dynamically and still
113+detect hover information.
114+-}
80115hoverables : a -> { events : Signal a,
81116 hoverable : (Bool -> a) -> Element -> Element }
82117hoverables = Native.Graphics.Input.hoverables
83118
84−-- Detect when the mouse is hovering over a specifici `Element`.
119+{-| Detect when the mouse is hovering over a specifici `Element`. -}
85120hoverable : Element -> (Element, Signal Bool)
86121hoverable elem =
87122 let pool = hoverables False
88123 in (pool.hoverable id elem, pool.events)
89124
90−-- Represents the current state of a text field. The `string` represents the
91−-- characters filling the text field. The `selectionStart` and `selectionEnd`
92−-- values represent what the user has selected with their mouse or keyboard.
93−-- For example:
94−--
95−-- { string="She sells sea shells", selectionStart=3, selectionEnd=0 }
96−--
97−-- This means the user highlighted the substring `"She"` backwards.
125+{-| Represents the current state of a text field. The `string` represents the
126+characters filling the text field. The `selectionStart` and `selectionEnd`
127+values represent what the user has selected with their mouse or keyboard.
128+For example:
129+
130+ { string="She sells sea shells", selectionStart=3, selectionEnd=0 }
131+
132+This means the user highlighted the substring `"She"` backwards.
133+-}
98134type FieldState = { string:String, selectionStart:Int, selectionEnd:Int }
99135
100−-- Create a group of text input fields.
101−--
102−-- * The first argument is the default value of the `events` signal.
103−-- * The `events` signal represents all of the activity in this group
104−-- of text fields.
105−-- * The `field` function creates a
106−-- field with the given ghost text and initial field state.
107−-- When the field is modified, the `(FieldState -> a)` function
108−-- takes the new state and turns
109−-- it into a value that can be sent to `events`. For example, this
110−-- lets you add an ID to distinguish between input fields.
136+{-| Create a group of text input fields.
137+
138+ * The first argument is the default value of the `events` signal.
139+ * The `events` signal represents all of the activity in this group
140+ of text fields.
141+ * The `field` function creates a
142+ field with the given ghost text and initial field state.
143+ When the field is modified, the `(FieldState -> a)` function
144+ takes the new state and turns
145+ it into a value that can be sent to `events`. For example, this
146+ lets you add an ID to distinguish between input fields.
147+-}
111148fields : a -> { events : Signal a,
112149 field : (FieldState -> a) -> String -> FieldState -> Element }
113150fields = Native.Graphics.Input.fields
114151
115−-- The empty field state:
116−--
117−-- { string="", selectionStart=0, selectionEnd=0 }
152+{-| The empty field state:
153+
154+ { string="", selectionStart=0, selectionEnd=0 }
155+-}
118156emptyFieldState : FieldState
119157emptyFieldState = { string="", selectionStart=0, selectionEnd=0 }
120158
121−-- Create a field with the given default text. The output is an element that
122−-- updates to match the user input and a signal of strings representing the
123−-- content of the field.
159+{-| Create a field with the given default text. The output is an element
160+that updates to match the user input and a signal of strings representing
161+the content of the field.
162+-}
124163field : String -> (Signal Element, Signal String)
125164field placeHolder =
126165 let tfs = fields emptyFieldState
@@ -128,7 +167,7 @@ field placeHolder =
128167 in (lift (tfs.field id placeHolder) changes,
129168 dropRepeats (lift .string changes))
130169
131−-- Same as `field` but the UI element blocks out each characters.
170+{-| Same as `field` but the UI element blocks out each characters. -}
132171password : String -> (Signal Element, Signal String)
133172password placeHolder =
134173 let tfs = Native.Graphics.Input.passwords emptyFieldState
@@ -136,9 +175,10 @@ password placeHolder =
136175 in (lift (tfs.field id placeHolder) changes,
137176 dropRepeats (lift .string changes))
138177
139−-- Same as `field` but it adds an annotation that this field is for email
140−-- addresses. This is helpful for auto-complete and for mobile users who may
141−-- get a custom keyboard with an `@` and `.com` button.
178+{-| Same as `field` but it adds an annotation that this field is for email
179+addresses. This is helpful for auto-complete and for mobile users who may
180+get a custom keyboard with an `@` and `.com` button.
181+-}
142182email : String -> (Signal Element, Signal String)
143183email placeHolder =
144184 let tfs = Native.Graphics.Input.emails emptyFieldState
@@ -146,15 +186,17 @@ email placeHolder =
146186 in (lift (tfs.field id placeHolder) changes,
147187 dropRepeats (lift .string changes))
148188
149−-- Create a drop-down menu. When the user selects a string,
150−-- the current state of the drop-down is set to the associated
151−-- value. This lets you avoid manually mapping the string onto
152−-- functions and values.
189+{-| Create a drop-down menu. When the user selects a string,
190+the current state of the drop-down is set to the associated
191+value. This lets you avoid manually mapping the string onto
192+functions and values.
193+-}
153194dropDown : [(String,a)] -> (Signal Element, Signal a)
154195dropDown = Native.Graphics.Input.dropDown
155196
156−-- Create a drop-down menu for selecting strings. The resulting
157−-- signal of strings represents the string that is currently selected.
197+{-| Create a drop-down menu for selecting strings. The resulting
198+signal of strings represents the string that is currently selected.
199+-}
158200stringDropDown : [String] -> (Signal Element, Signal String)
159201stringDropDown strs =
160202 dropDown (List.map (\s -> (s,s)) strs)
libraries/List.elm+106−64
@@ -4,128 +4,163 @@ module List where
44import open Basics
55import Native.List
66
7−-- Add an element to the front of a list `(1 :: [2,3] == [1,2,3])`
7+{-| DOCUMENT STRUCTURE
8+
9+A library for manipulating lists of values. Every value in a list must have
10+the same type.
11+
12+# Basics
13+@docs (::), (++), length, reverse, map
14+
15+# Sub-lists
16+@docs head, tail, last, filter, take, drop
17+
18+# Putting Lists Together
19+@docs concat, concatMap, join, intersperse, zip, zipWith
20+
21+# Taking Lists Apart
22+@docs split, partition, unzip
23+
24+# Folds
25+@docs foldr, foldl, foldr1, foldl1, scanl, scanl1
26+
27+# Special Folds
28+@docs susm, product, maximum, minimum, all, any, and, or
29+
30+-}
31+
32+{-| Add an element to the front of a list `(1 :: [2,3] == [1,2,3])` -}
833(::) : a -> [a] -> [a]
934(::) = Native.List.cons
1035
11−-- Puts two appendable things together:
12−--
13−-- [1,1] ++ [2,3] == [1,1,2,3]
14−-- "abc" ++ "123" == "abc123"
36+{-| Puts two appendable things together:
37+
38+ [1,1] ++ [2,3] == [1,1,2,3]
39+ "abc" ++ "123" == "abc123"
40+-}
1541(++) : appendable -> appendable -> appendable
1642(++) = Native.List.append
1743
18−-- Extract the first element of a list. List must be non-empty.
19−-- `(head [1,2,3] == 1)`
44+{-| Extract the first element of a list. List must be non-empty.
45+`(head [1,2,3] == 1)`
46+-}
2047head : [a] -> a
2148head = Native.List.head
2249
23−-- Extract the elements after the head of the list. List must be non-empty.
24−-- `(tail [1,2,3] == [2,3])`
50+{-| Extract the elements after the head of the list. List must be non-empty.
51+`(tail [1,2,3] == [2,3])`
52+-}
2553tail : [a] -> [a]
2654tail = Native.List.tail
2755
28−-- Extract the last element of a list. List must be non-empty.
29−-- `(last [1,2,3] == 3)`
56+{-| Extract the last element of a list. List must be non-empty.
57+`(last [1,2,3] == 3)`
58+-}
3059last : [a] -> a
3160last = Native.List.last
3261
33−-- Check if a list is empty `(isEmpty [] == True)`
62+{-| Check if a list is empty `(isEmpty [] == True)` -}
3463isEmpty : [a] -> Bool
3564isEmpty xs =
3665 case xs of
3766 [] -> True
3867 _ -> False
3968
40−-- Apply a function to every element of a list: `(map sqrt [1,4,9] == [1,2,3])`
69+{-| Apply a function to every element of a list: `(map sqrt [1,4,9] == [1,2,3])` -}
4170map : (a -> b) -> [a] -> [b]
4271map = Native.List.map
4372
44−-- Reduce a list from the left: `(foldl (::) [] "gateman" == "nametag")`
73+{-| Reduce a list from the left: `(foldl (::) [] "gateman" == "nametag")` -}
4574foldl : (a -> b -> b) -> b -> [a] -> b
4675foldl = Native.List.foldl
4776
48−-- Reduce a list from the right: `(foldr (+) 0 [1,2,3] == 6)`
77+{-| Reduce a list from the right: `(foldr (+) 0 [1,2,3] == 6)` -}
4978foldr : (a -> b -> b) -> b -> [a] -> b
5079foldr = Native.List.foldr
5180
52−-- Reduce a list from the left without a base case. List must be non-empty.
81+{-| Reduce a list from the left without a base case. List must be non-empty. -}
5382foldl1 : (a -> a -> a) -> [a] -> a
5483foldl1 = Native.List.foldl1
5584
56−-- Reduce a list from the right without a base case. List must be non-empty.
85+{-| Reduce a list from the right without a base case. List must be non-empty. -}
5786foldr1 : (a -> a -> a) -> [a] -> a
5887foldr1 = Native.List.foldr1
5988
60−-- Reduce a list from the left, building up all of the intermediate results into a list.
61−--
62−-- scanl (+) 0 [1,2,3,4] == [0,1,3,6,10]
89+{-| Reduce a list from the left, building up all of the intermediate results into a list.
90+
91+ scanl (+) 0 [1,2,3,4] == [0,1,3,6,10]
92+-}
6393scanl : (a -> b -> b) -> b -> [a] -> [b]
6494scanl = Native.List.scanl
6595
66−-- Same as scanl but it doesn't require a base case. List must be non-empty.
67−--
68−-- scanl1 (+) [1,2,3,4] == [1,3,6,10]
96+{-| Same as scanl but it doesn't require a base case. List must be non-empty.
97+
98+ scanl1 (+) [1,2,3,4] == [1,3,6,10]
99+-}
69100scanl1 : (a -> a -> a) -> [a] -> [a]
70101scanl1 = Native.List.scanl1
71102
72−-- Filter out elements which do not satisfy the predicate: `(filter isLower "AaBbCc" == "abc")`
103+{-| Keep only elements that satisfy the predicate:
104+`(filter isLower "AaBbCc" == "abc")`
105+-}
73106filter : (a -> Bool) -> [a] -> [a]
74107filter = Native.List.filter
75108
76−-- Determine the length of a list: `(length "innumerable" == 11)`
109+{-| Determine the length of a list: `(length "innumerable" == 11)` -}
77110length : [a] -> Int
78111length = Native.List.length
79112
80−-- Reverse a list. `(reverse [1..4] == [4,3,2,1])`
113+{-| Reverse a list. `(reverse [1..4] == [4,3,2,1])` -}
81114reverse : [a] -> [a]
82115reverse = Native.List.reverse
83116
84−-- Check to see if all elements satisfy the predicate.
117+{-| Check to see if all elements satisfy the predicate. -}
85118all : (a -> Bool) -> [a] -> Bool
86119all = Native.List.all
87120
88−-- Check to see if any elements satisfy the predicate.
121+{-| Check to see if any elements satisfy the predicate. -}
89122any : (a -> Bool) -> [a] -> Bool
90123any = Native.List.any
91124
92−-- Check to see if all elements are True.
125+{-| Check to see if all elements are True. -}
93126and : [Bool] -> Bool
94127and = foldl (&&) True
95128
96−-- Check to see if any elements are True.
129+{-| Check to see if any elements are True. -}
97130or : [Bool] -> Bool
98131or = foldl (||) False
99132
100−-- Concatenate a list of appendable things:
101−--
102−-- concat ["tree","house"] == "treehouse"
133+{-| Concatenate a list of appendable things:
134+
135+ concat ["tree","house"] == "treehouse"
136+-}
103137concat : [appendable] -> appendable
104138concat = Native.List.concat
105139
106−-- Map a given function onto a list and flatten the resulting lists.
107−--
108−-- concatMap f xs == concat (map f xs)
140+{-| Map a given function onto a list and flatten the resulting lists.
141+
142+ concatMap f xs == concat (map f xs)
143+-}
109144concatMap : (a -> appendable) -> [a] -> appendable
110145concatMap f list = concat (map f list)
111146
112−-- Get the sum of the list elements. `(sum [1..4] == 10)`
147+{-| Get the sum of the list elements. `(sum [1..4] == 10)` -}
113148sum : [number] -> number
114149sum = foldl (+) 0
115150
116−-- Get the product of the list elements. `(product [1..4] == 24)`
151+{-| Get the product of the list elements. `(product [1..4] == 24)` -}
117152product : [number] -> number
118153product = foldl (*) 1
119154
120−-- Find the maximum element in a non-empty list: `maximum [1,4,2] == 4`
155+{-| Find the maximum element in a non-empty list: `maximum [1,4,2] == 4` -}
121156maximum : [comparable] -> comparable
122157maximum = foldl1 max
123158
124−-- Find the minimum element in a non-empty list: `minimum [3,2,1] == 1`
159+{-| Find the minimum element in a non-empty list: `minimum [3,2,1] == 1` -}
125160minimum : [comparable] -> comparable
126161minimum = foldl1 min
127162
128−-- Split a list based on the predicate.
163+{-| Split a list based on the predicate. -}
129164partition : (a -> Bool) -> [a] -> ([a],[a])
130165partition pred lst =
131166 case lst of
@@ -133,44 +168,49 @@ partition pred lst =
133168 x::xs -> let (bs,cs) = partition pred xs in
134169 if pred x then (x::bs,cs) else (bs,x::cs)
135170
136−-- Combine two lists, combining them into tuples pairwise.
137−-- If one list is longer, the extra elements are dropped.
138−--
139−-- zip [1,2,3] [6,7] == [(1,6),(2,7)]
140−-- zip == zipWith (,)
171+{-| Combine two lists, combining them into tuples pairwise.
172+If one list is longer, the extra elements are dropped.
173+
174+ zip [1,2,3] [6,7] == [(1,6),(2,7)]
175+ zip == zipWith (,)
176+-}
141177zip : [a] -> [b] -> [(a,b)]
142178zip = Native.List.zip
143179
144−-- Combine two lists, combining them with the given function.
145−-- If one list is longer, the extra elements are dropped.
146−--
147−-- zipWith (+) [1,2,3] [1,2,3,4] == [2,4,6]
180+{-| Combine two lists, combining them with the given function.
181+If one list is longer, the extra elements are dropped.
182+
183+ zipWith (+) [1,2,3] [1,2,3,4] == [2,4,6]
184+-}
148185zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
149186zipWith = Native.List.zipWith
150187
151−-- Decompose a list of tuples.
188+{-| Decompose a list of tuples. -}
152189unzip : [(a,b)] -> ([a],[b])
153190unzip pairs =
154191 case pairs of
155192 [] -> ([],[])
156193 (x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
157194
158−-- Split a list with a given seperator.
159−--
160−-- split "," "hello,there,friend" == ["hello", "there", "friend"]
195+{-| Split a list with a given seperator.
196+
197+ split "," "hello,there,friend" == ["hello", "there", "friend"]
198+-}
161199split : [a] -> [a] -> [[a]]
162200split = Native.List.split
163201
164−-- Places the given value between all of the lists in the second argument
165−-- and concatenates the result.
166−--
167−-- join "a" ["H","w","ii","n"] == "Hawaiian"
202+{-| Places the given value between all of the lists in the second
203+argument and concatenates the result.
204+
205+ join "a" ["H","w","ii","n"] == "Hawaiian"
206+-}
168207join : appendable -> [appendable] -> appendable
169208join = Native.List.join
170209
171−-- Places the given value between all members of the given list.
172−--
173−-- intersperse ' ' "INCEPTION" == "I N C E P T I O N"
210+{-| Places the given value between all members of the given list.
211+
212+ intersperse ' ' "INCEPTION" == "I N C E P T I O N"
213+-}
174214intersperse : a -> [a] -> [a]
175215intersperse sep xs =
176216 case xs of
@@ -178,14 +218,16 @@ intersperse sep xs =
178218 [a] -> [a]
179219 [] -> []
180220
181−-- Take the first n members of a list: `(take 2 [1,2,3,4] == [1,2])`
221+{-| Take the first n members of a list: `(take 2 [1,2,3,4] == [1,2])` -}
182222take : Int -> [a] -> [a]
183223take = Native.List.take
184224
185−-- Drop the first n members of a list: `(drop 2 [1,2,3,4] == [3,4])`
225+{-| Drop the first n members of a list: `(drop 2 [1,2,3,4] == [3,4])` -}
186226drop : Int -> [a] -> [a]
187227drop = Native.List.drop
188228
189−-- Creates a list with n copies of a value: `(replicate 3 (0,0) == [(0,0),(0,0),(0,0)]`
229+{-| Creates a list with *n* copies of a value:
230+`(repeat 3 (0,0) == [(0,0),(0,0),(0,0)]`
231+-}
190232repeat : Int -> a -> [a]
191233repeat = Native.List.repeat