Hi ,
I met a problem caused by the tricky Indentation, here is the code looks in VI :
1 import Data.List
2 myQuickSort [] = []
3 myQuickSort (x:xs) = myQuickSort smaller ++ [x] ++ myQuickSort bigger
4 where smaller = filter ( < x ) xs
5 bigger = filter ( >=x ) xs
But after ./cat 3.hs , It looks ,
root@pierr-desktop:/opt/playGround/haskell# cat 3.hs
import Data.List
myQuickSort [] = []
myQuickSort (x:xs) = myQuickSort smaller ++ [x] ++ myQuickSort bigger
where smaller = filter ( < x ) xs
bigger = filter ( >=x ) xs
Then load it in ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help
Loading package base ... linking ... done.
Prelude> :l 3.hs
[1 of 1] Compiling Main ( 3.hs, interpreted )
3.hs:5:11: parse error on input `='
Failed, modules loaded: none.
Prelude>
How should I catch this invisible indentation error when programming haskell?
EDIT: Write it this way , the error will go. Is it a recommendded way to write the where binding - put variables in different lines as where?
myQuickSort [] = []
myQuickSort (x:xs) = myQuickSort smaller ++ [x] ++ myQuickSort bigger
where
smaller = filter (<x) xs
bigger = filter (>=x) xs