Haldean Brown
Haldean Brown

Reputation: 12721

"Possibly incorrect indentation" in Haskell case statement

I've been fooling around with the indentation on this for a while now, but it looks correct to me. Can anyone see where I'm going wrong?

deposit :: NodeType -> NodeType -> Amount -> Node
deposit (Income income) (Account bal grow) amount =
  Account (bal + transfer) grow where transfer = case amount of
    AbsoluteAmount amount  -> min income amount -- This is line 34
    RelativeAmount percent -> (min 1.0 percent) * income

The error message I'm getting is:

Prelude> :load BudgetFlow.hs 
[1 of 1] Compiling Main             ( BudgetFlow.hs, interpreted )

BudgetFlow.hs:34:5: parse error (possibly incorrect indentation)
Failed, modules loaded: none.

Line 34 (the line with the parse error) is the line that begins AbsoluteAmount (I marked it with a comment above). I've tried putting the case statement on its own line and indenting the two cases fully to the right of the of keyword, but I still get the same error message. Thanks so much for any help!

Upvotes: 2

Views: 630

Answers (1)

Don Stewart
Don Stewart

Reputation: 137987

Put the where clause on its own line.

deposit :: NodeType -> NodeType -> Amount -> Node
deposit (Income income) (Account bal grow) amount = Account (bal + transfer) grow
    where
        transfer = case amount of
            AbsoluteAmount amount  -> min income amount -- This is line 34
            RelativeAmount percent -> (min 1.0 percent) * income

Upvotes: 4

Related Questions