I’ve written following code:
module Test where
import Char
import IO
main = do
str <- readFile "no.txt"
putStrLn (show(english str))
string2list :: String -> [String]
string2list "" = []
string2list s = words s
english :: String -> Int
english s
| head (string2list s) == "one" = 1
| head (string2list s) == "two" = 2
| head (string2list s) == "three" = 3
| head (string2list s) == "four" = 4
| head (string2list s) == "five" = 5
| head (string2list s) == "six" = 6
| head (string2list s) == "seven" = 7
| head (string2list s) == "eight" = 8
| head (string2list s) == "nine" = 9
| otherwise = error "not match"
And in no.txt:
one
two
three
four
....
After compiled and run the code, I got the result:
1
But I expect to get:
1
2
3
4
...
What’s wrong with the code? Any help? thx!
stris not list of String (it’s just a String likeone\ntwo) when read fromreadFile. Doin your
maininstead and convertstrto a list usinglines(see doc of lines ).