*Main> zip [1 .. 10] "abcde" [(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e')] *Main> :t (:) (:) :: a -> [a] -> [a] *Main> 'a' : ['b', 'c', 'd'] "abcd" *Main> :r [1 of 1] Compiling Main ( lec3.hs, interpreted ) Ok, one module loaded. *Main> zip' [1 .. 10] "abcde" [(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e')] *Main> zip' [] "abcde" [] *Main> :t reverse reverse :: [a] -> [a] *Main> reverse "abcde" "edcba" *Main> reverse [1..10] [10,9,8,7,6,5,4,3,2,1] *Main> :r [1 of 1] Compiling Main ( lec3.hs, interpreted ) Ok, one module loaded. *Main> reverse' [1 .. 10] [10,9,8,7,6,5,4,3,2,1] *Main> :r [1 of 1] Compiling Main ( lec3.hs, interpreted ) Ok, one module loaded. *Main> reverse'' [1..10] [10,9,8,7,6,5,4,3,2,1] *Main> (\ x -> x + 1) 10 11 *Main> :t (\ x -> x + 1) (\ x -> x + 1) :: Num a => a -> a *Main> :t (\ x -> (\ y -> x + y)) (\ x -> (\ y -> x + y)) :: Num a => a -> a -> a *Main> (\ x -> (\ y -> x + y)) 10 4 14 *Main> :t (\ x -> (\ y -> x + y)) 10 (\ x -> (\ y -> x + y)) 10 :: Num a => a -> a *Main> (\ x -> (\ y -> x + y)) 10 :19:1: error: • No instance for (Show (Integer -> Integer)) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?) • In a stmt of an interactive GHCi command: print it *Main> *Main> *Main> *Main> *Main> *Main> *Main> map (\ x -> x + 1) [1 .. 10] [2,3,4,5,6,7,8,9,10,11] *Main> :t map (\ x -> [x, ',']) "abc" map (\ x -> [x, ',']) "abc" :: [[Char]] *Main> map (\ x -> [x, ',']) "abc" ["a,","b,","c,"] *Main> :t concat concat :: Foldable t => t [a] -> [a] *Main> concat (map (\ x -> [x, ',']) "abc") "a,b,c," *Main> :r [1 of 1] Compiling Main ( lec3.hs, interpreted ) Ok, one module loaded. *Main> map' (\ x -> x + 1) [1 .. 10] [2,3,4,5,6,7,8,9,10,11] *Main> :t filter filter :: (a -> Bool) -> [a] -> [a] *Main> filter even [1 .. 10] [2,4,6,8,10] *Main> filter (\ x -> x > 4) [1 .. 10] [5,6,7,8,9,10] *Main> filter (\ x -> x == 'r') "helloworld" "r" *Main> length (filter (\ x -> x == 'r') "helloworld") 1 *Main> length (filter (\ x -> x == 'l') "helloworld") 3 *Main> length (filter (\ x -> x == 'z') "helloworld") 0 *Main> :r [1 of 1] Compiling Main ( lec3.hs, interpreted ) Ok, one module loaded. *Main> filter' (\ x -> x == 'l') "helloworld" "lll" *Main> :t zipWith zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] *Main> zipWith (\ x y -> (x, y)) [1..10] "helloworld" [(1,'h'),(2,'e'),(3,'l'),(4,'l'),(5,'o'),(6,'w'),(7,'o'),(8,'r'),(9,'l'),(10,'d')] *Main> :t zipWith (\ x y -> (x, y)) zipWith (\ x y -> (x, y)) :: [a] -> [b] -> [(a, b)] *Main> :t show show :: Show a => a -> String *Main> show 1 "1" *Main> zipWith (\ x y -> x + y) [1..10] [11 .. 21] [12,14,16,18,20,22,24,26,28,30] *Main> zipWith (\ x y -> x + y) [1..10] [11 .. 20] [12,14,16,18,20,22,24,26,28,30] *Main> :r [1 of 1] Compiling Main ( lec3.hs, interpreted ) lec3.hs:46:19: error: • Couldn't match type ‘b’ with ‘c’ ‘b’ is a rigid type variable bound by the type signature for: zipWith' :: forall a b c. (a -> b -> c) -> [a] -> [b] -> [c] at lec3.hs:45:1-46 ‘c’ is a rigid type variable bound by the type signature for: zipWith' :: forall a b c. (a -> b -> c) -> [a] -> [b] -> [c] at lec3.hs:45:1-46 Expected type: [c] Actual type: [b] • In the expression: y In an equation for ‘zipWith'’: zipWith' f [] y = y • Relevant bindings include y :: [b] (bound at lec3.hs:46:15) f :: a -> b -> c (bound at lec3.hs:46:10) zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] (bound at lec3.hs:46:1) | 46 | zipWith' f [] y = y | ^ Failed, no modules loaded. Prelude> :r [1 of 1] Compiling Main ( lec3.hs, interpreted ) Ok, one module loaded. *Main> zipWith' (\ x y -> x + y) [1..10] [11 .. 20] [12,14,16,18,20,22,24,26,28,30]