GHCi中的隐形缩进错误导致加载失败 [英] Invisible indentation error caused load failure in GHCi
问题描述
<$ c $我遇到了一个由棘手的缩进引起的问题,这里是 c> 1 import Data.List
2 myQuickSort [] = []
3 myQuickSort(x:xs)= myQuickSort小++ [x] ++ myQuickSort大$ b $ 4其中small = filter (< x)xs
5 greater = filter(> = x)xs
但是在./cat 3.hs之后,看起来,
root @ pierr-desktop:/ opt / playGround / haskell#cat 3.hs
import Data.List
myQuickSort [] = []
myQuickSort(x:xs)= myQuickSort小++ [x] ++ myQuickSort大
where小= (< x)xs
greater = filter(> = x)xs
然后将其加载到ghci中。
GHCi,版本6.8.2:http://www.haskell.org/ghc/:?寻求帮助
加载程序包基础...链接...完成。
前奏> :l 3.hs
[1的1]编译主(3.hs,解释)
3.hs:5:11:解析输入错误`='
失败,模块加载:无。
前奏>
在编程haskell时,我应该如何捕捉到这个看不见的缩进错误?
编辑:
这样写,错误就会消失。这是一个推荐的方式来写在哪里绑定 - 把变量放在不同的行中?
myQuickSort [] = []
myQuickSort(x:xs)= myQuickSort小++ [x] ++ myQuickSort large
其中
smaller = filter(< x)xs
larger = filter(> = x)xs
您的问题与选项卡的扩展有关。 Haskell假设一个标签值8个空格。你的编辑可能有不同的假设。尝试搜索并用编辑器中的8个空格替换所有标签,然后调整空格以排列where子句。
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
Your problem has to do with the expansion of tabs. Haskell assumes a tab is worth 8 spaces. Your editor likely has a different assumption. Try searching and replacing all tabs with 8 space in your editor, then adjust the spacing to line up the where clause.
这篇关于GHCi中的隐形缩进错误导致加载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!