我遇到了棘手的缩进造成的问题,这里的代码看起来 是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
Run Code Online (Sandbox Code Playgroud)
但是在./cat 3.hs之后,看起来,
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
Run Code Online (Sandbox Code Playgroud)
然后将其加载到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>
Run Code Online (Sandbox Code Playgroud)
编程haskell时如何捕获这个不可见的缩进错误?
编辑:这样写,错误就会出现.它是一种推荐的方式来编写where binding - 把变量放在不同的行中吗?
myQuickSort [] = []
myQuickSort (x:xs) = myQuickSort smaller ++ [x] ++ myQuickSort bigger
where
smaller = filter (<x) xs
bigger = filter (>=x) xs
Run Code Online (Sandbox Code Playgroud)