5 import Prelude hiding (catch)
7 -- This module briefly tests all the functions in PrelList and a few
10 -- ToDo: test strictness properties.
15 print (head [1,2,3,4], head "a")
16 catch (print (head [] :: String)) (\_ -> putStr "head []\n")
19 print (tail [1,2,3,4], tail "a")
20 catch (print (tail [] :: String)) (\_ -> putStr "tail []\n")
23 print (init [1,2,3,4], init "a")
24 catch (print (init [] :: String)) (\_ -> putStr "init []\n")
27 print (last [1,2,3,4], last "a")
28 catch (print (last [] :: String)) (\_ -> putStr "last []\n")
31 print [null [], null "abc"]
34 print (length [1..10])
37 print (foldl (+) 1 [1..10])
40 print (foldl1 (+) [1..10])
41 catch (print (foldl1 (+) [] :: Int)) (\_ -> putStr "foldl1 []\n")
44 print (scanl (+) 1 [1..10])
47 print (scanl1 (+) [1..10])
48 catch (print (scanl1 (+) [] :: [Int])) (\_ -> putStr "scanl1 []\n")
51 print (foldr1 (+) [1..10])
52 catch (print (foldr1 (+) [] :: Int)) (\_ -> putStr "foldr1 []\n")
55 print (scanr (+) 1 [1..10])
58 print (scanr1 (+) [1..10])
59 catch (print (scanr1 (+) [] :: [Int])) (\_ -> putStr "scanr1 []\n")
62 print (take 10 (cycle (take 4 (iterate (+1) 1))))
65 print (take 4 (repeat "x"), take 0 (repeat "x"), take 5 [1..4])
66 catch (print (take (-1) [1..10])) (\_ -> putStr "take (-1)\n")
69 print [replicate 2 "abc", replicate 0 "abc", replicate 3 []]
72 print [drop 5 [1..10], drop 0 [1..10], drop 5 [1..4]]
73 catch (print (drop (-1) [1..10])) (\_ -> putStr "drop (-1)\n")
76 print [splitAt 5 [1..10], splitAt 5 [1..4]]
77 catch (print (splitAt (-1) [1..10])) (\_ -> putStr "splitAt (-1)\n")
80 print (span (<5) [1..10])
83 print (break (<5) [1..10])
86 print [reverse [1..10], reverse []]
89 print [and [], and [True], and [False]]
92 print [or [], or [True], or [False]]
95 print [elem 5 [1..10], elem 0 [1..10], elem 1 []]
98 print [notElem 5 [1..10], notElem 0 [1..10], notElem 1 []]
101 print (lookup 4 (zip [1..10] (reverse [1..10])))
104 print [sum [1..10], sum []]
107 print [product [1..10], product []]
110 print (maximum [1..10])
111 catch (print (maximum [] :: Int)) (\_ -> putStr "maximum []\n")
114 print (minimum [1..10])
115 catch (print (minimum [] :: Int)) (\_ -> putStr "minimum []\n")
118 print (concatMap (:[]) [(1::Int)..10])
121 print [zip [1] [2], zip [1] [], zip [] [2], zip [1..5] [2..6]]
124 print (zip3 [1,2] [3,4] [5,6])
127 print [zipWith (+) [1,2] [3,4], zipWith (+) [1] [], zipWith (+) [] []]
130 print [unzip [(1,2),(3,4)], unzip []]
133 print [unzip3 [(1,2,3),(3,4,5)], unzip3 []]
136 print (unlines (lines "a\nb\nc\n"), lines "", unlines [])
139 print (unwords (words "a b c d"), words "", unwords [])
142 print [deleteBy (==) 1 [0,1,1,2,3,4],
143 deleteBy (==) (error "deleteBy") []]
146 print [delete 1 [0,1,1,2,3,4],
147 delete (error "delete") []]
150 print [ [0,1,1,2,3,4] \\ [3,2,1],
152 [] \\ [error "\\\\"] ]