foFox
foFox

Reputation: 1124

Haskell incorrect indentation

I have an error saying "Possibly incorrect indentation"

boyerMooreSearch :: [Char] -> [Char] -> [Int] -> Int
boyerMooreSearch string pattern skipTable 
                                    | skip == 0                                     = 0
                                    | skip > 0 && (string length > pattern length)  = boyerMooreSearch (substring string skip (string length)) pattern skipTable
                                    | otherwise                                     = -1
                                    where 
                                    subStr = (substring 0 (pattern length)) 
                                    skip = (calculateSkip subStr pattern skipTable)

Whats wrong with it? Can anyone explain indentation rules in Haskell?

Upvotes: 0

Views: 208

Answers (1)

Daniel Wagner
Daniel Wagner

Reputation: 152737

On the line with substr, you have a string of whitespace followed by a literal tab character, and on the line with skip you have the same string followed by four spaces. These are incompatible; one robust, flexible way to get this right is to line things in a block up with exact the same string of whitespace at the beginning of each line.

The real rule, though, since you asked, is that tabs increase the indentation level to the next multiple of eight, and all other characters increase the indentation level by one. Different lines in a block must be at the same indentation level. do, where, let, and of introduce blocks (I may be forgetting a few).

Upvotes: 4

Related Questions