[Haskell-beginners] indentation

Daniel Fischer daniel.is.fischer at web.de
Sun Feb 14 15:20:23 EST 2010


Am Sonntag 14 Februar 2010 20:54:54 schrieb John Moore:
> Hi all,
>          I must be doing something wrong with my tabs. Because this
> keeps telling me parse error. Can some one see if it is indentation. I'm
> sending a file so as you'll be able to see what going on. If I copy it
> here it can appear wrong the difference is with the Var expression.
>
> John

First of all, *don't mix tabs and spaces for indentation* (best, don't use 
tabs at all).

It's

evalStep d (Var x)
     = case x of
	(Val a) ->case x of
	  (Val b) ->(lookup x d)
	  if (isJust m_e)then
	   evalStep(lookup x d)
	   else
            fail "Error in expression -- no definition for variable!"

The "if ... " is aligned with (Val b), so GHC tries to parse it as a 
pattern. But if-expressions aren't patterns, so you get a parse error.

But the code doesn't really make sense (and isn't well typed) anyway.
You probably want something like

evalStep d (Var x)
    = case lookup x d of
        Just e -> e
        Nothing -> error "Error in expression -- no definition for 
variable!"

for that.


More information about the Beginners mailing list