Consider the following piece of operational Haskell code :
Code A
describeList :: [a] -> String
describeList xs = "The list is " ++ what xs
where what [] = "empty."
what [x] = "a singleton list."
what xs = "a longer list."
which is a snippet taken from Syntax in Functions. Now suppose that we start off with the following piece of badly indented and non-operational Haskell code :
Code B
describeList :: [a] -> String
describeList xs = "The list is " ++ what xs
where what [] = "empty."
what [x] = "a singleton list."
what xs = "a longer list."
Then is there any tool which can take the badly indented code (Code B) and correctly indents it so as to yield operational code (Code A)?
This is next to impossible to do (and I’m writing this as a response because I’ve been looking for a tool myself that can do this) because unindented Haskell code can be very ambiguous.
Consider the code:
Let’s also consider some alternative, also valid, interpretations: