Reputation: 485
I have the following code, designed to take a duple from m
and replace the the duple that starts with s
with the evaluation of expression e
exec (Assign s e) m = assign s (eval e m) m
where assign _ _ [] = error ("undef var " ++ s)
assign s v (x:xs)
| fst x == s = if sameKind v (fst x)
then (fst x,v):xs
else error "type error in assign"
| otherwise = x:(assign s v xs)
where sameKind (VInt a) (VInt b) = True
sameKind (VBool a) (VBool b) = True
sameKind _ _ = False
When compiling, I get the error: parse error on input '|'
Does anybody know how to fix this?
Upvotes: 2
Views: 4078
Reputation: 4635
According to the Haskell 98 report:
Tab stops are 8 characters apart.
Your code appears to be designed for 5 (?) space tabs; change your editor's tab settings or stop using tabs and the problem will go away.
The reason is: Haskell thinks you indented it like this:
where assign _ _ [] = error ("undef var " ++ s)
assign s v (x:xs)
which, as you can see, means the start of the second definition is still inside the RHS of the first definition.
Also:
Don't do this:
where f [] = one_expr
f (x:xn) = another_expr
since it can make it hard to pick the where
keyword and the first equation apart from each other, and also since it means you depend on what Haskell thinks the relative width of the where
keyword and your indentation is, which is what bit you this time. Tabs are fine in Haskell as long as you only depend on the leading indentation on a given line and are consistent, but that means you always need to have a line break (and further indent) after where
, let
, case
/of
, do
, and possibly others I'm forgetting. (Except do
and let
when the whole construct is on one line, of course).
Upvotes: 5