Hi i’m getting a (Line 7) Parse error in input “=” for this which just sums the words in a string, any help is appreciated. Thanks.
module Main where
main = do
putStr "Enter a string: "
input <- getContents
value = unwords . sum . words input
putStrLn (value)
The line:
Is not syntactically valid. You need a let statement.
This still isn’t valid, you want to apply your function (well, composition of three functions) to the input:
or perhaps:
This still isn’t valid because the input is a
Stringand the result ofwordsis a list ofString([String]). So you’ll want to read the strings into someNumtype (Integers?) then convert back toString.unwordsis not useful because you only have one word, the sum, left at the end (vs a list of words, which unwords would need):Depending on the type, you might want to annotate the read or the sum to specify if it’s an
Intor aDoubleor something else.