0
有人可以幫我嗎?我試圖運行average
功能,但我得到的是讀取錯誤「(語法錯誤)上輸入‘::’」此代碼:Haskell顯示解析錯誤
sum` :: [Int] -> Int
sum` [] = 0
sum` (x:xs) = x + sum` xs
length` :: [a] -> Int
length` [] = 0
length` (x:xs) = 1 + length` xs
average :: [Int] -> Rational
average [] = error "empty list"
average xs = toRational (sum xs)/toRational(length xs)
非常感謝
我不認爲你可以使用單引號('''),請嘗試使用單引號(''') –
它的工作原理謝謝 – Kevin
@JosephYoung因爲您的評論解決了這個問題,你可以發佈它作爲一個回答所以可以接受? – sclv