mcgovec9
mcgovec9

Reputation: 71

haskell error on input else

having a bit of trouble with the following code. I keep getting an error message "saying parse error on input 'else' ". I cant see what im doing wrong, i have the else statement indented from the if and the syntax inside the statements are correct. Bit of background, its part of an insertion method for 2-3-4 trees, specifically for inserting where a fournode(Root3) needs to be split into its parent. x y and z are the values in the fournode while c1 - c4 are its child nodes. have looked at other questions on here about these types of errors but couldn't find anything useful :( Anyone have any ideas?

insert t (Root1 a left right) | t <= a = case left of
(Root3 x y z c1 c2 c3 c4) -> if t <= y then Root2 y a (insert t (Root1 x c1 c2) (Root1 z c3 c4) right else Root2 y a (Root1 x c1 c2) (insert t (Root1 z c3 c4)) right
_ -> Root1 a (insert t(left)) (right)

Upvotes: 0

Views: 297

Answers (2)

amalloy
amalloy

Reputation: 91837

Your indentation has mixed tabs and spaces, which is a big no-no: indentation is very significant in Haskell, and you want to make sure that what you see is the same as what the compiler sees. Just because a tab looks about as wide as eight spaces doesn't mean you can put one in instead of the eight spaces.

I recommend you fix this to use spaces-only, make sure things are lined up correctly, and then if you're still having issues ask a new question.

Upvotes: 0

jamshidh
jamshidh

Reputation: 12060

There may be other errors, but immediately I can see that your parenthesis aren't matched.... Take a look at the parens in the then. The compiler doesn't expect the else until after the then clause is finished, but the missing end paren is keeping this from happening.

Upvotes: 1

Related Questions