0
當試圖編譯我的代碼我得到:哈斯克爾:無法匹配,期望型「IO T0」與實際類型「整型」
[1 of 1] Compiling Main (survey2.hs, survey2.o)
survey2.hs:20:1:
Couldn't match expected type ‘IO t0’ with actual type ‘Integer’
In the expression: main
When checking the type of the IO action ‘main’
我試着指定「9亂搞'作爲一組不同的類型輸入到主體,包括IO,IO t,IO t0,int等等。據我所知,基於我在其他地方的函數定義,如果Integer沒有輸入到函數中沒有其他功能可以正常工作。我不知道如何把正確的類型放入主要。
factorial:: Integer -> Integer
factorial n
| n <= 1 = 1
| otherwise = n * factorial(n-1)
binomial :: (Integer, Integer) -> Integer
binomial (n, k)
| k > n = 0
| k < 0 = 0
| otherwise = factorial(n)/(factorial(n-k) * factorial(k))
bell :: Integer -> Integer
bell n
| n <= 1 = 1
| otherwise = sum [ binomial(n-1, k-1) * bell (k-1) | k<-[0..n-1] ]
bellSum :: Integer -> Integer
bellSum n = sum [ bell(k) | k<-[0..n] ]
main = bell(9 :: Integer)