@@ -41,11 +41,15 @@ import Basics (..)
4141import Maybe ( Maybe(Just,Nothing) )
4242import Native.List
4343
44−{-| Add an element to the front of a list `(1 :: [2,3] == [1,2,3])` -}
44+{-| Add an element to the front of a list. Pronounced *cons*.
45+
46+ 1 :: [2,3] == [1,2,3]
47+ 1 :: [] == [1]
48+-}
4549(::) : a -> [a] -> [a]
4650(::) = Native.List.cons
4751
48−{-| Puts two appendable things together:
52+{-| Put two appendable things together.
4953
5054 [1,1] ++ [2,3] == [1,1,2,3]
5155 "abc" ++ "123" == "abc123"
@@ -57,31 +61,40 @@ infixr 5 ::
5761infixr 5 ++
5862
5963{-| Extract the first element of a list. List must be non-empty.
60−`(head [1,2,3] == 1)`
64+
65+ head [1,2,3] == 1
6166-}
6267head : [a] -> a
6368head = Native.List.head
6469
6570{-| Extract the elements after the head of the list. List must be non-empty.
66−`(tail [1,2,3] == [2,3])`
71+
72+ tail [1,2,3] == [2,3]
6773-}
6874tail : [a] -> [a]
6975tail = Native.List.tail
7076
7177{-| Extract the last element of a list. List must be non-empty.
72−`(last [1,2,3] == 3)`
78+
79+ last [1,2,3] == 3
7380-}
7481last : [a] -> a
7582last = Native.List.last
7683
77−{-| Check if a list is empty `(isEmpty [] == True)` -}
84+{-| Determine if a list is empty.
85+
86+ isEmpty [] == True
87+-}
7888isEmpty : [a] -> Bool
7989isEmpty xs =
8090 case xs of
8191 [] -> True
8292 _ -> False
8393
84−{-| Apply a function to every element of a list: `(map sqrt [1,4,9] == [1,2,3])` -}
94+{-| Apply a function to every element of a list.
95+
96+ map sqrt [1,4,9] == [1,2,3]
97+-}
8598map : (a -> b) -> [a] -> [b]
8699map = Native.List.map
87100
@@ -94,11 +107,17 @@ indexedMap : (Int -> a -> b) -> [a] -> [b]
94107indexedMap f xs =
95108 zipWith f [ 0 .. length xs - 1 ] xs
96109
97−{-| Reduce a list from the left: `(foldl (::) [] [1,2,3] == [3,2,1])` -}
110+{-| Reduce a list from the left.
111+
112+ foldl (::) [] [1,2,3] == [3,2,1]
113+-}
98114foldl : (a -> b -> b) -> b -> [a] -> b
99115foldl = Native.List.foldl
100116
101−{-| Reduce a list from the right: `(foldr (+) 0 [1,2,3] == 6)` -}
117+{-| Reduce a list from the right.
118+
119+ foldr (+) 0 [1,2,3] == 6
120+-}
102121foldr : (a -> b -> b) -> b -> [a] -> b
103122foldr = Native.List.foldr
104123
@@ -124,8 +143,9 @@ scanl = Native.List.scanl
124143scanl1 : (a -> a -> a) -> [a] -> [a]
125144scanl1 = Native.List.scanl1
126145
127−{-| Keep only elements that satisfy the predicate:
128−`(filter isEven [1..6] == [2,4,6])`
146+{-| Keep only elements that satisfy the predicate.
147+
148+ filter isEven [1..6] == [2,4,6]
129149-}
130150filter : (a -> Bool) -> [a] -> [a]
131151filter = Native.List.filter
@@ -133,9 +153,7 @@ filter = Native.List.filter
133153{-| Apply a function that may succeed to all values in the list, but only keep
134154the successes.
135155
136− toInt : String -> Maybe Int
137−
138− filterMap toInt ["3", "4.0", "5", "hats"] == [3,5]
156+ filterMap String.toInt ["3", "4.0", "5", "hats"] == [3,5]
139157-}
140158filterMap : (a -> Maybe b) -> [a] -> [b]
141159filterMap f xs = foldr (maybeCons f) [] xs
@@ -146,19 +164,35 @@ maybeCons f mx xs =
146164 Just x -> x :: xs
147165 Nothing -> xs
148166
149−{-| Determine the length of a list: `(length [1,2,3] == 3)` -}
167+{-| Determine the length of a list.
168+
169+ length [1,2,3] == 3
170+-}
150171length : [a] -> Int
151172length = Native.List.length
152173
153−{-| Reverse a list. `(reverse [1..4] == [4,3,2,1])` -}
174+{-| Reverse a list.
175+
176+ reverse [1..4] == [4,3,2,1]
177+-}
154178reverse : [a] -> [a]
155179reverse = Native.List.reverse
156180
157−{-| Check to see if all elements satisfy the predicate. -}
181+{-| Determine if all elements satisfy the predicate.
182+
183+ all isEven [2,4] == True
184+ all isEven [2,3] == False
185+ all isEven [] == True
186+-}
158187all : (a -> Bool) -> [a] -> Bool
159188all = Native.List.all
160189
161−{-| Check to see if any elements satisfy the predicate. -}
190+{-| Determine if any elements satisfy the predicate.
191+
192+ any isEven [2,3] == True
193+ any isEven [1,3] == False
194+ any isEven [] == False
195+-}
162196any : (a -> Bool) -> [a] -> Bool
163197any = Native.List.any
164198
@@ -177,19 +211,27 @@ concat = Native.List.concat
177211concatMap : (a -> appendable) -> [a] -> appendable
178212concatMap f list = concat (map f list)
179213
180−{-| Get the sum of the list elements. `(sum [1..4] == 10)` -}
214+{-| Get the sum of the list elements.
215+ sum [1..4] == 10
216+-}
181217sum : [number] -> number
182218sum = foldl (+) 0
183219
184−{-| Get the product of the list elements. `(product [1..4] == 24)` -}
220+{-| Get the product of the list elements.
221+ product [1..4] == 24
222+-}
185223product : [number] -> number
186224product = foldl (*) 1
187225
188−{-| Find the maximum element in a non-empty list: `maximum [1,4,2] == 4` -}
226+{-| Find the maximum element in a non-empty list.
227+ maximum [1,4,2] == 4
228+-}
189229maximum : [comparable] -> comparable
190230maximum = foldl1 max
191231
192−{-| Find the minimum element in a non-empty list: `minimum [3,2,1] == 1` -}
232+{-| Find the minimum element in a non-empty list.
233+ minimum [3,2,1] == 1
234+-}
193235minimum : [comparable] -> comparable
194236minimum = foldl1 min
195237
@@ -242,7 +284,7 @@ zipWith4 = Native.List.zipWith4
242284zipWith5 : (a -> b -> c -> d -> e -> x) -> [a] -> [b] -> [c] -> [d] -> [e] -> [x]
243285zipWith5 = Native.List.zipWith5
244286
245−{-| Decompose a list of tuples.
287+{-| Decompose a list of tuples into a tuple of lists.
246288
247289 unzip [(0, True), (17, False), (1337, True)] == ([0,17,1337], [True,False,True])
248290-}
@@ -251,8 +293,7 @@ unzip =
251293 let step (x,y) (xs, ys) = (x::xs, y::ys)
252294 in foldr step ([], [])
253295
254−{-| Places the given value between all of the lists in the second
255−argument and concatenates the result.
296+{-| Place a value between all elements in a list and concatenates the result.
256297
257298 join "a" ["H","w","ii","n"] == "Hawaiian"
258299-}
@@ -272,21 +313,30 @@ intersperse sep xs =
272313 spersed = foldr step [] tl
273314 in hd :: spersed
274315
275−{-| Take the first n members of a list: `(take 2 [1,2,3,4] == [1,2])` -}
316+{-| Take the first *n* members of a list.
317+
318+ take 2 [1,2,3,4] == [1,2]
319+-}
276320take : Int -> [a] -> [a]
277321take = Native.List.take
278322
279−{-| Drop the first n members of a list: `(drop 2 [1,2,3,4] == [3,4])` -}
323+{-| Drop the first *n* members of a list.
324+
325+ drop 2 [1,2,3,4] == [3,4]
326+-}
280327drop : Int -> [a] -> [a]
281328drop = Native.List.drop
282329
283−{-| Creates a list with *n* copies of a value:
284−`(repeat 3 (0,0) == [(0,0),(0,0),(0,0)]`
330+{-| Create a list with *n* copies of a value:
331+
332+ repeat 3 (0,0) == [(0,0),(0,0),(0,0)]
285333-}
286334repeat : Int -> a -> [a]
287335repeat = Native.List.repeat
288336
289−{-| Sort values from lowest to highest: `sort [3,1,5] == [1,3,5]`
337+{-| Sort values from lowest to highest
338+
339+ sort [3,1,5] == [1,3,5]
290340-}
291341sort : [comparable] -> [comparable]
292342sort = Native.List.sort