@@ -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,9 @@ 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
156+ String.toInt : String -> Maybe Int
137157
138− filterMap toInt ["3", "4.0", "5", "hats"] == [3,5]
158+ filterMap String.toInt ["3", "4.0", "5", "hats"] == [3,5]
139159-}
140160filterMap : (a -> Maybe b) -> [a] -> [b]
141161filterMap f xs = foldr (maybeCons f) [] xs
@@ -146,19 +166,35 @@ maybeCons f mx xs =
146166 Just x -> x :: xs
147167 Nothing -> xs
148168
149−{-| Determine the length of a list: `(length [1,2,3] == 3)` -}
169+{-| Determine the length of a list.
170+
171+ length [1,2,3] == 3
172+-}
150173length : [a] -> Int
151174length = Native.List.length
152175
153−{-| Reverse a list. `(reverse [1..4] == [4,3,2,1])` -}
176+{-| Reverse a list.
177+
178+ reverse [1..4] == [4,3,2,1]
179+-}
154180reverse : [a] -> [a]
155181reverse = Native.List.reverse
156182
157−{-| Check to see if all elements satisfy the predicate. -}
183+{-| Determine if all elements satisfy the predicate.
184+
185+ all isEven [2,4] == True
186+ all isEven [2,3] == False
187+ all isEven [] == True
188+-}
158189all : (a -> Bool) -> [a] -> Bool
159190all = Native.List.all
160191
161−{-| Check to see if any elements satisfy the predicate. -}
192+{-| Determine if any elements satisfy the predicate.
193+
194+ any isEven [2,3] == True
195+ any isEven [1,3] == False
196+ any isEven [] == False
197+-}
162198any : (a -> Bool) -> [a] -> Bool
163199any = Native.List.any
164200
@@ -177,19 +213,28 @@ concat = Native.List.concat
177213concatMap : (a -> appendable) -> [a] -> appendable
178214concatMap f list = concat (map f list)
179215
180−{-| Get the sum of the list elements. `(sum [1..4] == 10)` -}
216+{-| Get the sum of the list elements.
217+
218+ sum [1..4] == 10
219+-}
181220sum : [number] -> number
182221sum = foldl (+) 0
183222
184−{-| Get the product of the list elements. `(product [1..4] == 24)` -}
223+{-| Get the product of the list elements.
224+ product [1..4] == 24
225+-}
185226product : [number] -> number
186227product = foldl (*) 1
187228
188−{-| Find the maximum element in a non-empty list: `maximum [1,4,2] == 4` -}
229+{-| Find the maximum element in a non-empty list.
230+ maximum [1,4,2] == 4
231+-}
189232maximum : [comparable] -> comparable
190233maximum = foldl1 max
191234
192−{-| Find the minimum element in a non-empty list: `minimum [3,2,1] == 1` -}
235+{-| Find the minimum element in a non-empty list.
236+ minimum [3,2,1] == 1
237+-}
193238minimum : [comparable] -> comparable
194239minimum = foldl1 min
195240
@@ -242,7 +287,7 @@ zipWith4 = Native.List.zipWith4
242287zipWith5 : (a -> b -> c -> d -> e -> x) -> [a] -> [b] -> [c] -> [d] -> [e] -> [x]
243288zipWith5 = Native.List.zipWith5
244289
245−{-| Decompose a list of tuples.
290+{-| Decompose a list of tuples into a tuple of lists.
246291
247292 unzip [(0, True), (17, False), (1337, True)] == ([0,17,1337], [True,False,True])
248293-}
@@ -251,8 +296,7 @@ unzip =
251296 let step (x,y) (xs, ys) = (x::xs, y::ys)
252297 in foldr step ([], [])
253298
254−{-| Places the given value between all of the lists in the second
255−argument and concatenates the result.
299+{-| Place a value between all elements in a list and concatenates the result.
256300
257301 join "a" ["H","w","ii","n"] == "Hawaiian"
258302-}
@@ -272,21 +316,30 @@ intersperse sep xs =
272316 spersed = foldr step [] tl
273317 in hd :: spersed
274318
275−{-| Take the first n members of a list: `(take 2 [1,2,3,4] == [1,2])` -}
319+{-| Take the first *n* members of a list.
320+
321+ take 2 [1,2,3,4] == [1,2]
322+-}
276323take : Int -> [a] -> [a]
277324take = Native.List.take
278325
279−{-| Drop the first n members of a list: `(drop 2 [1,2,3,4] == [3,4])` -}
326+{-| Drop the first *n* members of a list.
327+
328+ drop 2 [1,2,3,4] == [3,4]
329+-}
280330drop : Int -> [a] -> [a]
281331drop = Native.List.drop
282332
283−{-| Creates a list with *n* copies of a value:
284−`(repeat 3 (0,0) == [(0,0),(0,0),(0,0)]`
333+{-| Create a list with *n* copies of a value:
334+
335+ repeat 3 (0,0) == [(0,0),(0,0),(0,0)]
285336-}
286337repeat : Int -> a -> [a]
287338repeat = Native.List.repeat
288339
289−{-| Sort values from lowest to highest: `sort [3,1,5] == [1,3,5]`
340+{-| Sort values from lowest to highest
341+
342+ sort [3,1,5] == [1,3,5]
290343-}
291344sort : [comparable] -> [comparable]
292345sort = Native.List.sort