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?

duplode
  • 33,731
  • 7
  • 79
  • 150
chowmean
  • 152
  • 1
  • 9
  • possible duplicate of [Haskell error parse error on input \`='](http://stackoverflow.com/questions/6184940/haskell-error-parse-error-on-input) (it is the mirrored version of this question, but the answers are just as relevant). – duplode Aug 14 '15 at 01:21

1 Answers1

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.

Ganesh Sittampalam
  • 28,821
  • 4
  • 79
  • 98
  • 2
    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. – Ørjan Johansen Jun 22 '14 at 15:38