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