リスト内のすべての要素の合計を取得しようとしています。そして、私は要素の量を持っています。私は、合計をこのリストのすべての要素の平均を得るための量で除算したいと思います。そして、部門は私に修正できないエラーを返します。 マイコード: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は型リストの2つのソネットです。私はSplitOnでテキストの文字列をリストに変換しました。 –