Reputation: 553
there is a question really confused me when i am running this piece of code
data Tree a = Nil | Node a (Tree a) (Tree a)
type IntTree = Tree Int
type Counter = State Int
withCounter::Int -> Counter a -> a
withCounter init f = fst(runState f init)
nextCount::Counter Int
nextCount = do
n <- get
put (n+1)
return n
incTree::IntTree -> IntTree
incTree tree = withCounter 1 (IncTree' tree)
incTree' Nil = return 0
incTree' (Node l e r) = do
newl <- incTree' l
n <- nextCount
newr <- incTree' r
return (Node newl (e+n) newr)
the error is as following:
parse error on input '<-'
and it appears to be raised at line 27, that is 'n <- nextCount'
does anyone know why i am getting this error ? thanks !
Upvotes: 0
Views: 440
Reputation: 47052
As you appear not to have copied and pasted your code directly, the answer is probably that you are mixing tab characters and spaces.
Do not use tabs: indent using spaces only.
Upvotes: 4