-4
我試圖獲得列表中所有元素的總和,到目前爲止有效。我有元素的數量。我想把總和除以數量得到此列表中所有元素的平均值。該部門給我一個我無法修復的錯誤。 我的代碼:Haskell中的分區由於類型錯誤而不工作
module HA
where
import FPH
import Data.List.Split
import Data.Char
import qualified Data.Text hiding (length)
s1 = splitOn " " sonnet18
s2 = splitOn " " sonnet73
countSubStrs str sub = length $ Data.Text.breakOnAll (Data.Text.pack sub) (Data.Text.pack str)
task :: IO()
task = do
let wordLengths = map length
let wl1 = wordLengths s1
let wl2 = wordLengths s2
let getsum1 = sum wl1
let ln [] = 0
let ln (x:xs) =1 + ln xs
let average = wl1 `quot` getsum1
print average
錯誤:
Couldn't match expected type '[Int]' with actual type 'Int'
In the second argument of `quot´, namely `getsum1´
In the expression: wl1 `quot´ getsum1
In an equation for `average´: average = wl1 `quot´ getsum1
什麼是's1'和's2'? – Sibi
請提供[MCVE](http://stackoverflow.com/help/mcve) –
哦,對不起。 s1和s2是類型列表的兩個十四行詩。我用SplitOn將文本字符串轉換爲列表。 –