From where can I get complete set of Indentation rules for Haskell code writing?
Past SO questions which are similar to my following question has led me to ask above question. What are the reasons behind the error message: parse error on input 'something'
?
Error message I got:
baby.hs:103:2: parse error on input `myList'(error in this line)
Code I am trying to compile:
myList = ["aeroplane", "Aeroplane", "AeRoPlAne", "helicopter", "HELICOPTER", "Zebra"]
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted
Edit by Optimight:
I shifted the code in the question to new .hs file and tried to compile it. Still similar error message remains. Details below:
Error
quickSort.hs:5:62: parse error on input `=' Failed, modules loaded: none. (0.02 secs, 0 bytes)Code quicksort :: (Ord a) => [a] -> [a]
quicksort [] = [] quicksort (x:xs) = let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted
myList = ["aeroplane", "Aeroplane", "AeRoPlAne", "helicopter", "HELICOPTER", "Zebra", "America"]
If I understood you correctly easiest way to avoid this problem is by writing single
do
andlet
like this:Main point here is that first indent at
exp1
is easy to spot and maintain in every new line.And here's copy/paste from my learning sheets. It's not much but might help someone. If anyone notice anything wrong/false please correct me.
At least for standard Haskell (without language extensions), the layout rules are explained in Section 10.3 of the Haskell 2010 report.
The report may be a bit formal for your taste. Various tutorials and textbooks on Haskell have some more informal explanations of the layout rules, for example the Haskell Wikibook.
In your particular case, the error message points to line 103, but you are only pasting a couple of lines. I can see that at least the indentation of the let-in construct is broken. You should write something like the following: