s4342re41
s4342re41

Reputation: 103

Parse Error (Possibly Incorrect Indentation...)

When I run this code:

test1 :: Int -> String
test1 x = do
    if x == 1
        then "Hello"

I get the following error:

test-if.hs:4:21: error:
    parse error (possibly incorrect indentation or mismatched brackets)

I am not sure why this is as I am not using any brackets and I am using 4 spaces as my tabs. Adding brackets doesn't seem to help. What could be the issue?

Thanks

Upvotes: 1

Views: 258

Answers (1)

sepp2k
sepp2k

Reputation: 370465

Your if needs an else (what do you want the value to be when x isn't 1?).

Furthermore do notation is used when working with monads and doesn't make sense in this function.

Upvotes: 5

Related Questions