on master help sign in
Change the style of some documentation, experimenting with styles for elm-doc
c4d0730Evan Czaplicki
libraries/Graphics/Input.elm+118−76
@@ -1,4 +1,3 @@
1−
2module Graphics.Input where
1module Graphics.Input where
3
2
4import Basics (String)
3import Basics (String)
@@ -9,118 +8,158 @@ import Graphics.Element (Element)
9import Maybe (Maybe)
8import Maybe (Maybe)
10import JavaScript (JSString)
9import JavaScript (JSString)
11
10
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+
12id x = x
40id x = x
13
41
14−-- Create a group of buttons.
42+{-| Create a group of buttons.
15−--
43+
16−-- * The first argument is the default value of the `events` signal.
44+ * The first argument is the default value of the `events` signal.
17−-- * The `events` signal represents all of the activity in this group
45+ * The `events` signal represents all of the activity in this group
18−-- of buttons.
46+ of buttons.
19−-- * The `button` function creates a button
47+ * The `button` function creates a button
20−-- with the given name, like “Submit” or “Cancel”.
48+ with the given name, like “Submit” or “Cancel”.
21−-- The `a` value is sent to `events` whenever the button is pressed.
49+ The `a` value is sent to `events` whenever the button is pressed.
50+-}
22buttons : a -> { events : Signal a,
51buttons : a -> { events : Signal a,
23 button : a -> String -> Element }
52 button : a -> String -> Element }
24buttons = Native.Graphics.Input.buttons
53buttons = Native.Graphics.Input.buttons
25
54
26−-- Create a button with a given label. The result is an `Element` and
55+{-| 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.
56+a signal of units. This signal triggers whenever the button is pressed.
57+-}
28button : String -> (Element, Signal ())
58button : String -> (Element, Signal ())
29button txt =
59button txt =
30 let pool = buttons ()
60 let pool = buttons ()
31 in (pool.button () txt, pool.events)
61 in (pool.button () txt, pool.events)
32
62
33−-- Create a group of custom buttons.
63+{-| Create a group of custom buttons.
34−--
64+
35−-- * The first argument is the default value of the `events` signal.
65+ * The first argument is the default value of the `events` signal.
36−-- * The `events` signal represents all of the activity in this group
66+ * The `events` signal represents all of the activity in this group
37−-- of custom buttons.
67+ of custom buttons.
38−-- * The `customButton` function creates a button with three different visual
68+ * The `customButton` function creates a button with three different visual
39−-- states, one for up, hovering, and down. The resulting button has dimensions
69+ states, one for up, hovering, and down. The resulting button has dimensions
40−-- large enough to fit all three possible `Elements`.
70+ large enough to fit all three possible `Elements`.
41−-- The `a` value is sent to `events` whenever the button is pressed.
71+ The `a` value is sent to `events` whenever the button is pressed.
72+-}
42customButtons : a -> { events : Signal a,
73customButtons : a -> { events : Signal a,
43 customButton : a -> Element -> Element -> Element -> Element }
74 customButton : a -> Element -> Element -> Element -> Element }
44customButtons = Native.Graphics.Input.customButtons
75customButtons = Native.Graphics.Input.customButtons
45
76
46−-- Create a button with custom states for up, hovering, and down
77+{-| Create a button with custom states for up, hovering, and down
47−-- (given in that order). The result is an `Element` and
78+(given in that order). The result is an `Element` and a signal of
48−-- a signal of units. This signal triggers whenever the button is pressed.
79+units. This signal triggers whenever the button is pressed.
80+-}
49customButton : Element -> Element -> Element -> (Element, Signal ())
81customButton : Element -> Element -> Element -> (Element, Signal ())
50customButton up hover down =
82customButton up hover down =
51 let pool = customButtons ()
83 let pool = customButtons ()
52 in (pool.customButton () up hover down, pool.events)
84 in (pool.customButton () up hover down, pool.events)
53
85
54−-- Create a group of checkboxes.
86+{-| Create a group of checkboxes.
55−--
87+
56−-- * The first argument is the default value of the `events` signal.
88+ * The first argument is the default value of the `events` signal.
57−-- * The `events` signal represents all of the activity in this group
89+ * The `events` signal represents all of the activity in this group
58−-- of checkboxes.
90+ of checkboxes.
59−-- * The `checkbox` function creates a
91+ * The `checkbox` function creates a
60−-- checkbox with a given state. The `(Bool -> a)` function is used
92+ checkbox with a given state. The `(Bool -> a)` function is used
61−-- when the checkbox is modified. It takes the new state and turns
93+ 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
94+ it into a value that can be sent to `events`. For example, this
63−-- lets you add an ID to distinguish between checkboxes.
95+ lets you add an ID to distinguish between checkboxes.
96+-}
64checkboxes : a -> { events : Signal a,
97checkboxes : a -> { events : Signal a,
65 checkbox : (Bool -> a) -> Bool -> Element }
98 checkbox : (Bool -> a) -> Bool -> Element }
66checkboxes = Native.Graphics.Input.checkboxes
99checkboxes = Native.Graphics.Input.checkboxes
67
100
68−-- Create a checkbox with a given start state. Unlike `button`, this result
101+{-| Create a checkbox with a given start state. Unlike `button`, this
69−-- is a *signal* of elements. That is because a checkbox has state that
102+result is a *signal* of elements. That is because a checkbox has state
70−-- updates based on user input.
103+that updates based on user input. The boolean signal represents the
71−-- The boolean signal represents the current state of the checkbox.
104+current state of the checkbox.
105+-}
72checkbox : Bool -> (Signal Element, Signal Bool)
106checkbox : Bool -> (Signal Element, Signal Bool)
73checkbox b =
107checkbox b =
74 let cbs = checkboxes b
108 let cbs = checkboxes b
75 in (lift (cbs.checkbox id) cbs.events, cbs.events)
109 in (lift (cbs.checkbox id) cbs.events, cbs.events)
76
110
77−-- Detect when the mouse is hovering over some elements. This
111+{-| Detect when the mouse is hovering over some elements. This
78−-- allows you to create and destroy elements dynamically and still
112+allows you to create and destroy elements dynamically and still
79−-- detect hover information.
113+detect hover information.
114+-}
80hoverables : a -> { events : Signal a,
115hoverables : a -> { events : Signal a,
81 hoverable : (Bool -> a) -> Element -> Element }
116 hoverable : (Bool -> a) -> Element -> Element }
82hoverables = Native.Graphics.Input.hoverables
117hoverables = Native.Graphics.Input.hoverables
83
118
84−-- Detect when the mouse is hovering over a specifici `Element`.
119+{-| Detect when the mouse is hovering over a specifici `Element`. -}
85hoverable : Element -> (Element, Signal Bool)
120hoverable : Element -> (Element, Signal Bool)
86hoverable elem =
121hoverable elem =
87 let pool = hoverables False
122 let pool = hoverables False
88 in (pool.hoverable id elem, pool.events)
123 in (pool.hoverable id elem, pool.events)
89
124
90−-- Represents the current state of a text field. The `string` represents the
125+{-| Represents the current state of a text field. The `string` represents the
91−-- characters filling the text field. The `selectionStart` and `selectionEnd`
126+characters filling the text field. The `selectionStart` and `selectionEnd`
92−-- values represent what the user has selected with their mouse or keyboard.
127+values represent what the user has selected with their mouse or keyboard.
93−-- For example:
128+For example:
94−--
129+
95−-- { string="She sells sea shells", selectionStart=3, selectionEnd=0 }
130+ { string="She sells sea shells", selectionStart=3, selectionEnd=0 }
96−--
131+
97−-- This means the user highlighted the substring `"She"` backwards.
132+This means the user highlighted the substring `"She"` backwards.
133+-}
98type FieldState = { string:String, selectionStart:Int, selectionEnd:Int }
134type FieldState = { string:String, selectionStart:Int, selectionEnd:Int }
99
135
100−-- Create a group of text input fields.
136+{-| Create a group of text input fields.
101−--
137+
102−-- * The first argument is the default value of the `events` signal.
138+ * The first argument is the default value of the `events` signal.
103−-- * The `events` signal represents all of the activity in this group
139+ * The `events` signal represents all of the activity in this group
104−-- of text fields.
140+ of text fields.
105−-- * The `field` function creates a
141+ * The `field` function creates a
106−-- field with the given ghost text and initial field state.
142+ field with the given ghost text and initial field state.
107−-- When the field is modified, the `(FieldState -> a)` function
143+ When the field is modified, the `(FieldState -> a)` function
108−-- takes the new state and turns
144+ takes the new state and turns
109−-- it into a value that can be sent to `events`. For example, this
145+ it into a value that can be sent to `events`. For example, this
110−-- lets you add an ID to distinguish between input fields.
146+ lets you add an ID to distinguish between input fields.
147+-}
111fields : a -> { events : Signal a,
148fields : a -> { events : Signal a,
112 field : (FieldState -> a) -> String -> FieldState -> Element }
149 field : (FieldState -> a) -> String -> FieldState -> Element }
113fields = Native.Graphics.Input.fields
150fields = Native.Graphics.Input.fields
114
151
115−-- The empty field state:
152+{-| The empty field state:
116−--
153+
117−-- { string="", selectionStart=0, selectionEnd=0 }
154+ { string="", selectionStart=0, selectionEnd=0 }
155+-}
118emptyFieldState : FieldState
156emptyFieldState : FieldState
119emptyFieldState = { string="", selectionStart=0, selectionEnd=0 }
157emptyFieldState = { string="", selectionStart=0, selectionEnd=0 }
120
158
121−-- Create a field with the given default text. The output is an element that
159+{-| Create a field with the given default text. The output is an element
122−-- updates to match the user input and a signal of strings representing the
160+that updates to match the user input and a signal of strings representing
123−-- content of the field.
161+the content of the field.
162+-}
124field : String -> (Signal Element, Signal String)
163field : String -> (Signal Element, Signal String)
125field placeHolder =
164field placeHolder =
126 let tfs = fields emptyFieldState
165 let tfs = fields emptyFieldState
@@ -128,7 +167,7 @@ field placeHolder =
128 in (lift (tfs.field id placeHolder) changes,
167 in (lift (tfs.field id placeHolder) changes,
129 dropRepeats (lift .string changes))
168 dropRepeats (lift .string changes))
130
169
131−-- Same as `field` but the UI element blocks out each characters.
170+{-| Same as `field` but the UI element blocks out each characters. -}
132password : String -> (Signal Element, Signal String)
171password : String -> (Signal Element, Signal String)
133password placeHolder =
172password placeHolder =
134 let tfs = Native.Graphics.Input.passwords emptyFieldState
173 let tfs = Native.Graphics.Input.passwords emptyFieldState
@@ -136,9 +175,10 @@ password placeHolder =
136 in (lift (tfs.field id placeHolder) changes,
175 in (lift (tfs.field id placeHolder) changes,
137 dropRepeats (lift .string changes))
176 dropRepeats (lift .string changes))
138
177
139−-- Same as `field` but it adds an annotation that this field is for email
178+{-| 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
179+addresses. This is helpful for auto-complete and for mobile users who may
141−-- get a custom keyboard with an `@` and `.com` button.
180+get a custom keyboard with an `@` and `.com` button.
181+-}
142email : String -> (Signal Element, Signal String)
182email : String -> (Signal Element, Signal String)
143email placeHolder =
183email placeHolder =
144 let tfs = Native.Graphics.Input.emails emptyFieldState
184 let tfs = Native.Graphics.Input.emails emptyFieldState
@@ -146,15 +186,17 @@ email placeHolder =
146 in (lift (tfs.field id placeHolder) changes,
186 in (lift (tfs.field id placeHolder) changes,
147 dropRepeats (lift .string changes))
187 dropRepeats (lift .string changes))
148
188
149−-- Create a drop-down menu. When the user selects a string,
189+{-| Create a drop-down menu. When the user selects a string,
150−-- the current state of the drop-down is set to the associated
190+the current state of the drop-down is set to the associated
151−-- value. This lets you avoid manually mapping the string onto
191+value. This lets you avoid manually mapping the string onto
152−-- functions and values.
192+functions and values.
193+-}
153dropDown : [(String,a)] -> (Signal Element, Signal a)
194dropDown : [(String,a)] -> (Signal Element, Signal a)
154dropDown = Native.Graphics.Input.dropDown
195dropDown = Native.Graphics.Input.dropDown
155
196
156−-- Create a drop-down menu for selecting strings. The resulting
197+{-| Create a drop-down menu for selecting strings. The resulting
157−-- signal of strings represents the string that is currently selected.
198+signal of strings represents the string that is currently selected.
199+-}
158stringDropDown : [String] -> (Signal Element, Signal String)
200stringDropDown : [String] -> (Signal Element, Signal String)
159stringDropDown strs =
201stringDropDown strs =
160 dropDown (List.map (\s -> (s,s)) strs)
202 dropDown (List.map (\s -> (s,s)) strs)
libraries/List.elm+106−64
@@ -4,128 +4,163 @@ module List where
4import open Basics
4import open Basics
5import Native.List
5import Native.List
6
6
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+
7−-- Add an element to the front of a list `(1 :: [2,3] == [1,2,3])`
32+{-| Add an element to the front of a list `(1 :: [2,3] == [1,2,3])` -}
8(::) : a -> [a] -> [a]
33(::) : a -> [a] -> [a]
9(::) = Native.List.cons
34(::) = Native.List.cons
10
35
11−-- Puts two appendable things together:
36+{-| Puts two appendable things together:
12−--
37+
13−-- [1,1] ++ [2,3] == [1,1,2,3]
38+ [1,1] ++ [2,3] == [1,1,2,3]
14−-- "abc" ++ "123" == "abc123"
39+ "abc" ++ "123" == "abc123"
40+-}
15(++) : appendable -> appendable -> appendable
41(++) : appendable -> appendable -> appendable
16(++) = Native.List.append
42(++) = Native.List.append
17
43
18−-- Extract the first element of a list. List must be non-empty.
44+{-| Extract the first element of a list. List must be non-empty.
19−-- `(head [1,2,3] == 1)`
45+`(head [1,2,3] == 1)`
46+-}
20head : [a] -> a
47head : [a] -> a
21head = Native.List.head
48head = Native.List.head
22
49
23−-- Extract the elements after the head of the list. List must be non-empty.
50+{-| Extract the elements after the head of the list. List must be non-empty.
24−-- `(tail [1,2,3] == [2,3])`
51+`(tail [1,2,3] == [2,3])`
52+-}
25tail : [a] -> [a]
53tail : [a] -> [a]
26tail = Native.List.tail
54tail = Native.List.tail
27
55
28−-- Extract the last element of a list. List must be non-empty.
56+{-| Extract the last element of a list. List must be non-empty.
29−-- `(last [1,2,3] == 3)`
57+`(last [1,2,3] == 3)`
58+-}
30last : [a] -> a
59last : [a] -> a
31last = Native.List.last
60last = Native.List.last
32
61
33−-- Check if a list is empty `(isEmpty [] == True)`
62+{-| Check if a list is empty `(isEmpty [] == True)` -}
34isEmpty : [a] -> Bool
63isEmpty : [a] -> Bool
35isEmpty xs =
64isEmpty xs =
36 case xs of
65 case xs of
37 [] -> True
66 [] -> True
38 _ -> False
67 _ -> False
39
68
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])` -}
41map : (a -> b) -> [a] -> [b]
70map : (a -> b) -> [a] -> [b]
42map = Native.List.map
71map = Native.List.map
43
72
44−-- Reduce a list from the left: `(foldl (::) [] "gateman" == "nametag")`
73+{-| Reduce a list from the left: `(foldl (::) [] "gateman" == "nametag")` -}
45foldl : (a -> b -> b) -> b -> [a] -> b
74foldl : (a -> b -> b) -> b -> [a] -> b
46foldl = Native.List.foldl
75foldl = Native.List.foldl
47
76
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)` -}
49foldr : (a -> b -> b) -> b -> [a] -> b
78foldr : (a -> b -> b) -> b -> [a] -> b
50foldr = Native.List.foldr
79foldr = Native.List.foldr
51
80
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. -}
53foldl1 : (a -> a -> a) -> [a] -> a
82foldl1 : (a -> a -> a) -> [a] -> a
54foldl1 = Native.List.foldl1
83foldl1 = Native.List.foldl1
55
84
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. -}
57foldr1 : (a -> a -> a) -> [a] -> a
86foldr1 : (a -> a -> a) -> [a] -> a
58foldr1 = Native.List.foldr1
87foldr1 = Native.List.foldr1
59
88
60−-- Reduce a list from the left, building up all of the intermediate results into a list.
89+{-| Reduce a list from the left, building up all of the intermediate results into a list.
61−--
90+
62−-- scanl (+) 0 [1,2,3,4] == [0,1,3,6,10]
91+ scanl (+) 0 [1,2,3,4] == [0,1,3,6,10]
92+-}
63scanl : (a -> b -> b) -> b -> [a] -> [b]
93scanl : (a -> b -> b) -> b -> [a] -> [b]
64scanl = Native.List.scanl
94scanl = Native.List.scanl
65
95
66−-- Same as scanl but it doesn't require a base case. List must be non-empty.
96+{-| Same as scanl but it doesn't require a base case. List must be non-empty.
67−--
97+
68−-- scanl1 (+) [1,2,3,4] == [1,3,6,10]
98+ scanl1 (+) [1,2,3,4] == [1,3,6,10]
99+-}
69scanl1 : (a -> a -> a) -> [a] -> [a]
100scanl1 : (a -> a -> a) -> [a] -> [a]
70scanl1 = Native.List.scanl1
101scanl1 = Native.List.scanl1
71
102
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+-}
73filter : (a -> Bool) -> [a] -> [a]
106filter : (a -> Bool) -> [a] -> [a]
74filter = Native.List.filter
107filter = Native.List.filter
75
108
76−-- Determine the length of a list: `(length "innumerable" == 11)`
109+{-| Determine the length of a list: `(length "innumerable" == 11)` -}
77length : [a] -> Int
110length : [a] -> Int
78length = Native.List.length
111length = Native.List.length
79
112
80−-- Reverse a list. `(reverse [1..4] == [4,3,2,1])`
113+{-| Reverse a list. `(reverse [1..4] == [4,3,2,1])` -}
81reverse : [a] -> [a]
114reverse : [a] -> [a]
82reverse = Native.List.reverse
115reverse = Native.List.reverse
83
116
84−-- Check to see if all elements satisfy the predicate.
117+{-| Check to see if all elements satisfy the predicate. -}
85all : (a -> Bool) -> [a] -> Bool
118all : (a -> Bool) -> [a] -> Bool
86all = Native.List.all
119all = Native.List.all
87
120
88−-- Check to see if any elements satisfy the predicate.
121+{-| Check to see if any elements satisfy the predicate. -}
89any : (a -> Bool) -> [a] -> Bool
122any : (a -> Bool) -> [a] -> Bool
90any = Native.List.any
123any = Native.List.any
91
124
92−-- Check to see if all elements are True.
125+{-| Check to see if all elements are True. -}
93and : [Bool] -> Bool
126and : [Bool] -> Bool
94and = foldl (&&) True
127and = foldl (&&) True
95
128
96−-- Check to see if any elements are True.
129+{-| Check to see if any elements are True. -}
97or : [Bool] -> Bool
130or : [Bool] -> Bool
98or = foldl (||) False
131or = foldl (||) False
99
132
100−-- Concatenate a list of appendable things:
133+{-| Concatenate a list of appendable things:
101−--
134+
102−-- concat ["tree","house"] == "treehouse"
135+ concat ["tree","house"] == "treehouse"
136+-}
103concat : [appendable] -> appendable
137concat : [appendable] -> appendable
104concat = Native.List.concat
138concat = Native.List.concat
105
139
106−-- Map a given function onto a list and flatten the resulting lists.
140+{-| Map a given function onto a list and flatten the resulting lists.
107−--
141+
108−-- concatMap f xs == concat (map f xs)
142+ concatMap f xs == concat (map f xs)
143+-}
109concatMap : (a -> appendable) -> [a] -> appendable
144concatMap : (a -> appendable) -> [a] -> appendable
110concatMap f list = concat (map f list)
145concatMap f list = concat (map f list)
111
146
112−-- Get the sum of the list elements. `(sum [1..4] == 10)`
147+{-| Get the sum of the list elements. `(sum [1..4] == 10)` -}
113sum : [number] -> number
148sum : [number] -> number
114sum = foldl (+) 0
149sum = foldl (+) 0
115
150
116−-- Get the product of the list elements. `(product [1..4] == 24)`
151+{-| Get the product of the list elements. `(product [1..4] == 24)` -}
117product : [number] -> number
152product : [number] -> number
118product = foldl (*) 1
153product = foldl (*) 1
119
154
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` -}
121maximum : [comparable] -> comparable
156maximum : [comparable] -> comparable
122maximum = foldl1 max
157maximum = foldl1 max
123
158
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` -}
125minimum : [comparable] -> comparable
160minimum : [comparable] -> comparable
126minimum = foldl1 min
161minimum = foldl1 min
127
162
128−-- Split a list based on the predicate.
163+{-| Split a list based on the predicate. -}
129partition : (a -> Bool) -> [a] -> ([a],[a])
164partition : (a -> Bool) -> [a] -> ([a],[a])
130partition pred lst =
165partition pred lst =
131 case lst of
166 case lst of
@@ -133,44 +168,49 @@ partition pred lst =
133 x::xs -> let (bs,cs) = partition pred xs in
168 x::xs -> let (bs,cs) = partition pred xs in
134 if pred x then (x::bs,cs) else (bs,x::cs)
169 if pred x then (x::bs,cs) else (bs,x::cs)
135
170
136−-- Combine two lists, combining them into tuples pairwise.
171+{-| Combine two lists, combining them into tuples pairwise.
137−-- If one list is longer, the extra elements are dropped.
172+If one list is longer, the extra elements are dropped.
138−--
173+
139−-- zip [1,2,3] [6,7] == [(1,6),(2,7)]
174+ zip [1,2,3] [6,7] == [(1,6),(2,7)]
140−-- zip == zipWith (,)
175+ zip == zipWith (,)
176+-}
141zip : [a] -> [b] -> [(a,b)]
177zip : [a] -> [b] -> [(a,b)]
142zip = Native.List.zip
178zip = Native.List.zip
143
179
144−-- Combine two lists, combining them with the given function.
180+{-| Combine two lists, combining them with the given function.
145−-- If one list is longer, the extra elements are dropped.
181+If one list is longer, the extra elements are dropped.
146−--
182+
147−-- zipWith (+) [1,2,3] [1,2,3,4] == [2,4,6]
183+ zipWith (+) [1,2,3] [1,2,3,4] == [2,4,6]
184+-}
148zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
185zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
149zipWith = Native.List.zipWith
186zipWith = Native.List.zipWith
150
187
151−-- Decompose a list of tuples.
188+{-| Decompose a list of tuples. -}
152unzip : [(a,b)] -> ([a],[b])
189unzip : [(a,b)] -> ([a],[b])
153unzip pairs =
190unzip pairs =
154 case pairs of
191 case pairs of
155 [] -> ([],[])
192 [] -> ([],[])
156 (x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
193 (x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
157
194
158−-- Split a list with a given seperator.
195+{-| Split a list with a given seperator.
159−--
196+
160−-- split "," "hello,there,friend" == ["hello", "there", "friend"]
197+ split "," "hello,there,friend" == ["hello", "there", "friend"]
198+-}
161split : [a] -> [a] -> [[a]]
199split : [a] -> [a] -> [[a]]
162split = Native.List.split
200split = Native.List.split
163
201
164−-- Places the given value between all of the lists in the second argument
202+{-| Places the given value between all of the lists in the second
165−-- and concatenates the result.
203+argument and concatenates the result.
166−--
204+
167−-- join "a" ["H","w","ii","n"] == "Hawaiian"
205+ join "a" ["H","w","ii","n"] == "Hawaiian"
206+-}
168join : appendable -> [appendable] -> appendable
207join : appendable -> [appendable] -> appendable
169join = Native.List.join
208join = Native.List.join
170
209
171−-- Places the given value between all members of the given list.
210+{-| Places the given value between all members of the given list.
172−--
211+
173−-- intersperse ' ' "INCEPTION" == "I N C E P T I O N"
212+ intersperse ' ' "INCEPTION" == "I N C E P T I O N"
213+-}
174intersperse : a -> [a] -> [a]
214intersperse : a -> [a] -> [a]
175intersperse sep xs =
215intersperse sep xs =
176 case xs of
216 case xs of
@@ -178,14 +218,16 @@ intersperse sep xs =
178 [a] -> [a]
218 [a] -> [a]
179 [] -> []
219 [] -> []
180
220
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])` -}
182take : Int -> [a] -> [a]
222take : Int -> [a] -> [a]
183take = Native.List.take
223take = Native.List.take
184
224
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])` -}
186drop : Int -> [a] -> [a]
226drop : Int -> [a] -> [a]
187drop = Native.List.drop
227drop = Native.List.drop
188
228
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+-}
190repeat : Int -> a -> [a]
232repeat : Int -> a -> [a]
191repeat = Native.List.repeat
233repeat = Native.List.repeat