No title

Anonymous Coward 2018-03-07 18:22:04.145378 UTC

1-- Exercises: Thy Fearful Symmetry
2
3-- Using takeWhile and dropWhile, write a function that takes a string
4-- and returns a list of strings, using spaces to separate the elements
5-- of the string into words, as in the following sample:
6-- Prelude> myWords "sheryl wants fun"
7-- ["wallfish", "wants", "fun"]
8
9
10mySplit :: String -> [String]
11mySplit [] = []
12mySplit xs = takeWhile (/= ' ') xs : mySplit $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
13
14
15Error messages :
16
17Lib.hs:45:14: error:
18 * Couldn't match expected type `[Char] -> [String]'
19 with actual type `[[Char]]'
20 * The first argument of ($) takes one argument,
21 but its type `[[Char]]' has none
22 In the expression:
23 takeWhile (/= ' ') xs : mySplit
24 $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
25 In an equation for `mySplit':
26 mySplit xs
27 = takeWhile (/= ' ') xs : mySplit
28 $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
29 |
3045 | mySplit xs = takeWhile (/= ' ') xs : mySplit $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
31 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32
33Lib.hs:45:38: error:
34 * Couldn't match expected type `[[Char]]'
35 with actual type `String -> [String]'
36 * Probable cause: `mySplit' is applied to too few arguments
37 In the second argument of `(:)', namely `mySplit'
38 In the expression: takeWhile (/= ' ') xs : mySplit
39 In the expression:
40 takeWhile (/= ' ') xs : mySplit
41 $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
42 |
4345 | mySplit xs = takeWhile (/= ' ') xs : mySplit $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
44 | ^^^^^^^
45Failed, no modules loaded.
46
47<no location info>: error:
48 Could not find module `Lib'
49 It is not a module in the current program, or in any known package.
50Loaded GHCi configuration from C:\Users\rwobb\AppData\Local\Temp\ghci2088\ghci-script
51[1 of 1] Compiling Lib ( Lib.hs, interpreted )
52
53Lib.hs:45:14: error:
54 * Couldn't match expected type `[Char] -> [String]'
55 with actual type `[[Char]]'
56 * The first argument of ($) takes one argument,
57 but its type `[[Char]]' has none
58 In the expression:
59 takeWhile (/= ' ') xs : mySplit
60 $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
61 In an equation for `mySplit':
62 mySplit xs
63 = takeWhile (/= ' ') xs : mySplit
64 $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
65 |
6645 | mySplit xs = takeWhile (/= ' ') xs : mySplit $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
67 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68
69Lib.hs:45:38: error:
70 * Couldn't match expected type `[[Char]]'
71 with actual type `String -> [String]'
72 * Probable cause: `mySplit' is applied to too few arguments
73 In the second argument of `(:)', namely `mySplit'
74 In the expression: takeWhile (/= ' ') xs : mySplit
75 In the expression:
76 takeWhile (/= ' ') xs : mySplit
77 $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
78 |
7945 | mySplit xs = takeWhile (/= ' ') xs : mySplit $ dropWhile (== ' ') $ dropWhile (/= ' ') xs
80 | ^^^^^^^
81Failed, no modules loaded.