因此,我試圖創建一個輔助函數來執行其他操作,但我甚至無法獲取過去幫助功能,因爲我不斷收到此錯誤:無法與實際類型'Int - > [t - > t1]'匹配預期類型'[Char]'
Couldn't match expected type ‘[Char]’ with actual type ‘Int -> [t -> t1]’
freqsHelper x = freqs (x (lowers x))
^
降低(x)導致此問題。這裏是我的代碼:
lowers [] = 0
lowers (x:xs)
| isLower x == True = 1 + lowers xs
| otherwise = lowers xs
count _ [] = 0
count x (y:ys)
| x == y = 1 + count x ys
| otherwise = count x ys
percent x y = x/y*100
freqsHelper x = freqs (x (lowers x))
freqs (x:xs) y = percent ((count (x (x:xs))) y) : freqs xs y
freq打算做什麼? – Carbon
像Davislor和MathematicalOrchid我建議你爲將來編寫的每個函數編寫類型聲明。它最終爲您節省了大量時間,因爲編譯器可以告訴您早期出錯的位置。類型系統是Haskell中最好的一個,所以你應該使用它來獲得你的優勢。如果你必須做一些類型驅動的編程,編寫類型聲明也可以幫助你。使用'InstanceSigs'擴展名,您還可以在任何類型的類中爲您的函數編寫類型聲明。 –