@@ -41,11 +41,15 @@ import Basics (..)
41import Maybe ( Maybe(Just,Nothing) )
41import Maybe ( Maybe(Just,Nothing) )
42import Native.List
42import Native.List
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*.
46+ 1 :: [2,3] == [1,2,3]
45(::) : a -> [a] -> [a]
49(::) : a -> [a] -> [a]
46(::) = Native.List.cons
50(::) = Native.List.cons
48−{-| Puts two appendable things together:
52+{-| Put two appendable things together.
50 [1,1] ++ [2,3] == [1,1,2,3]
54 [1,1] ++ [2,3] == [1,1,2,3]
51 "abc" ++ "123" == "abc123"
55 "abc" ++ "123" == "abc123"
@@ -57,31 +61,40 @@ infixr 5 ::
57infixr 5 ++
61infixr 5 ++
59{-| Extract the first element of a list. List must be non-empty.
63{-| Extract the first element of a list. List must be non-empty.
60−`(head [1,2,3] == 1)`
65+ head [1,2,3] == 1
62head : [a] -> a
67head : [a] -> a
63head = Native.List.head
68head = Native.List.head
65{-| Extract the elements after the head of the list. List must be non-empty.
70{-| Extract the elements after the head of the list. List must be non-empty.
66−`(tail [1,2,3] == [2,3])`
72+ tail [1,2,3] == [2,3]
68tail : [a] -> [a]
74tail : [a] -> [a]
69tail = Native.List.tail
75tail = Native.List.tail
71{-| Extract the last element of a list. List must be non-empty.
77{-| Extract the last element of a list. List must be non-empty.
72−`(last [1,2,3] == 3)`
79+ last [1,2,3] == 3
74last : [a] -> a
81last : [a] -> a
75last = Native.List.last
82last = Native.List.last
84+{-| Determine if a list is empty.
77−{-| Check if a list is empty `(isEmpty [] == True)` -}
86+ isEmpty [] == True
78isEmpty : [a] -> Bool
88isEmpty : [a] -> Bool
79isEmpty xs =
89isEmpty xs =
80 case xs of
90 case xs of
81 [] -> True
91 [] -> True
82 _ -> False
92 _ -> False
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.
96+ map sqrt [1,4,9] == [1,2,3]
85map : (a -> b) -> [a] -> [b]
98map : (a -> b) -> [a] -> [b]
86map = Native.List.map
99map = Native.List.map
@@ -94,11 +107,17 @@ indexedMap : (Int -> a -> b) -> [a] -> [b]
94indexedMap f xs =
107indexedMap f xs =
95 zipWith f [ 0 .. length xs - 1 ] xs
108 zipWith f [ 0 .. length xs - 1 ] xs
97−{-| Reduce a list from the left: `(foldl (::) [] [1,2,3] == [3,2,1])` -}
110+{-| Reduce a list from the left.
112+ foldl (::) [] [1,2,3] == [3,2,1]
98foldl : (a -> b -> b) -> b -> [a] -> b
114foldl : (a -> b -> b) -> b -> [a] -> b
99foldl = Native.List.foldl
115foldl = Native.List.foldl
101−{-| Reduce a list from the right: `(foldr (+) 0 [1,2,3] == 6)` -}
117+{-| Reduce a list from the right.
119+ foldr (+) 0 [1,2,3] == 6
102foldr : (a -> b -> b) -> b -> [a] -> b
121foldr : (a -> b -> b) -> b -> [a] -> b
103foldr = Native.List.foldr
122foldr = Native.List.foldr
@@ -124,8 +143,9 @@ scanl = Native.List.scanl
124scanl1 : (a -> a -> a) -> [a] -> [a]
143scanl1 : (a -> a -> a) -> [a] -> [a]
125scanl1 = Native.List.scanl1
144scanl1 = Native.List.scanl1
127−{-| Keep only elements that satisfy the predicate:
146+{-| Keep only elements that satisfy the predicate.
128−`(filter isEven [1..6] == [2,4,6])`
148+ filter isEven [1..6] == [2,4,6]
130filter : (a -> Bool) -> [a] -> [a]
150filter : (a -> Bool) -> [a] -> [a]
131filter = Native.List.filter
151filter = Native.List.filter
@@ -133,9 +153,9 @@ filter = Native.List.filter
133{-| Apply a function that may succeed to all values in the list, but only keep
153{-| Apply a function that may succeed to all values in the list, but only keep
134the successes.
154the successes.
136− toInt : String -> Maybe Int
156+ String.toInt : String -> Maybe Int
138− filterMap toInt ["3", "4.0", "5", "hats"] == [3,5]
158+ filterMap String.toInt ["3", "4.0", "5", "hats"] == [3,5]
140filterMap : (a -> Maybe b) -> [a] -> [b]
160filterMap : (a -> Maybe b) -> [a] -> [b]
141filterMap f xs = foldr (maybeCons f) [] xs
161filterMap f xs = foldr (maybeCons f) [] xs
@@ -146,19 +166,35 @@ maybeCons f mx xs =
146 Just x -> x :: xs
166 Just x -> x :: xs
147 Nothing -> xs
167 Nothing -> xs
149−{-| Determine the length of a list: `(length [1,2,3] == 3)` -}
169+{-| Determine the length of a list.
150length : [a] -> Int
173length : [a] -> Int
151length = Native.List.length
174length = Native.List.length
153−{-| Reverse a list. `(reverse [1..4] == [4,3,2,1])` -}
178+ reverse [1..4] == [4,3,2,1]
154reverse : [a] -> [a]
180reverse : [a] -> [a]
155reverse = Native.List.reverse
181reverse = Native.List.reverse
157−{-| Check to see if all elements satisfy the predicate. -}
183+{-| Determine if all elements satisfy the predicate.
185+ all isEven [2,4] == True
186+ all isEven [2,3] == False
187+ all isEven [] == True
158all : (a -> Bool) -> [a] -> Bool
189all : (a -> Bool) -> [a] -> Bool
159all = Native.List.all
190all = Native.List.all
161−{-| Check to see if any elements satisfy the predicate. -}
192+{-| Determine if any elements satisfy the predicate.
194+ any isEven [2,3] == True
195+ any isEven [1,3] == False
196+ any isEven [] == False
162any : (a -> Bool) -> [a] -> Bool
198any : (a -> Bool) -> [a] -> Bool
163any = Native.List.any
199any = Native.List.any
@@ -177,19 +213,28 @@ concat = Native.List.concat
177concatMap : (a -> appendable) -> [a] -> appendable
213concatMap : (a -> appendable) -> [a] -> appendable
178concatMap f list = concat (map f list)
214concatMap f list = concat (map f list)
180−{-| Get the sum of the list elements. `(sum [1..4] == 10)` -}
216+{-| Get the sum of the list elements.
181sum : [number] -> number
220sum : [number] -> number
182sum = foldl (+) 0
221sum = foldl (+) 0
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
185product : [number] -> number
226product : [number] -> number
186product = foldl (*) 1
227product = foldl (*) 1
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
189maximum : [comparable] -> comparable
232maximum : [comparable] -> comparable
190maximum = foldl1 max
233maximum = foldl1 max
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
193minimum : [comparable] -> comparable
238minimum : [comparable] -> comparable
194minimum = foldl1 min
239minimum = foldl1 min
@@ -242,7 +287,7 @@ zipWith4 = Native.List.zipWith4
242zipWith5 : (a -> b -> c -> d -> e -> x) -> [a] -> [b] -> [c] -> [d] -> [e] -> [x]
287zipWith5 : (a -> b -> c -> d -> e -> x) -> [a] -> [b] -> [c] -> [d] -> [e] -> [x]
243zipWith5 = Native.List.zipWith5
288zipWith5 = Native.List.zipWith5
245−{-| Decompose a list of tuples.
290+{-| Decompose a list of tuples into a tuple of lists.
247 unzip [(0, True), (17, False), (1337, True)] == ([0,17,1337], [True,False,True])
292 unzip [(0, True), (17, False), (1337, True)] == ([0,17,1337], [True,False,True])
@@ -251,8 +296,7 @@ unzip =
251 let step (x,y) (xs, ys) = (x::xs, y::ys)
296 let step (x,y) (xs, ys) = (x::xs, y::ys)
252 in foldr step ([], [])
297 in foldr step ([], [])
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.
257 join "a" ["H","w","ii","n"] == "Hawaiian"
301 join "a" ["H","w","ii","n"] == "Hawaiian"
@@ -272,21 +316,30 @@ intersperse sep xs =
272 spersed = foldr step [] tl
316 spersed = foldr step [] tl
273 in hd :: spersed
317 in hd :: spersed
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.
321+ take 2 [1,2,3,4] == [1,2]
276take : Int -> [a] -> [a]
323take : Int -> [a] -> [a]
277take = Native.List.take
324take = Native.List.take
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.
328+ drop 2 [1,2,3,4] == [3,4]
280drop : Int -> [a] -> [a]
330drop : Int -> [a] -> [a]
281drop = Native.List.drop
331drop = Native.List.drop
283−{-| Creates a list with *n* copies of a value:
333+{-| Create a list with *n* copies of a value:
284−`(repeat 3 (0,0) == [(0,0),(0,0),(0,0)]`
335+ repeat 3 (0,0) == [(0,0),(0,0),(0,0)]
286repeat : Int -> a -> [a]
337repeat : Int -> a -> [a]
287repeat = Native.List.repeat
338repeat = Native.List.repeat
289−{-| Sort values from lowest to highest: `sort [3,1,5] == [1,3,5]`
340+{-| Sort values from lowest to highest
342+ sort [3,1,5] == [1,3,5]
291sort : [comparable] -> [comparable]
344sort : [comparable] -> [comparable]
292sort = Native.List.sort
345sort = Native.List.sort