1
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?

1
  • possible duplicate of Haskell error parse error on input `=' (it is the mirrored version of this question, but the answers are just as relevant). Commented Aug 14, 2015 at 1:21

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is for top level in a file, of course. At the GHCi prompt let is required, which is probably what's causing the confusion. This is a leftover from when GHCi syntax was essentially inside a "do block", although nowadays it otherwise supports most of the same declarations as at file top level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.