Reputation: 152
import Data.Char (digitToInt)
let f [] = []
f ('\n':',':a) = f ('\n' : a)
f (a:b) = a : f b
main :: IO ()
main = do
ln<-getLine
f ln
print dp
getting parse error on input `='
Why is that so?
Upvotes: 1
Views: 222
Reputation: 29110
In Haskell source files, top-level definitions like f
shouldn't be introduced with a let
- just write
f [] = []
f ('\n':',':a) = f ('\n' : a)
f (a:b) = a : f b
Also you need make sure that the left-hand side of each clause in a definition lines up in the same column, as Haskell is indentation-aware. So in this case the f
in each clause should be at the very start of each line, as above.
Note that the ghci prompt behaves more like you're inside a do
block, and so let
is valid, which can be a source of confusion when moving between the two.
Upvotes: 5