我目前已定义了两个功能:
avg :: (Fractional e) => [e] -> e
avg e = uncurry (/) $ foldl' (\(a,l) v -> (a+v,l+1)) (0.0,0.0) e
avgOf :: (Fractional a) => Getting (Endo (Endo (a, a))) s a -> s -> a
avgOf g s = uncurry (/) $ foldlOf' g accfun (0.0,0.0) s
where accfun (a,l) v = (a+v, l+1)
我的印象是,必须有一种简单的方法来摆脱整个avgOf
实现,并用一个简单的方法来取代它,只需“提升”avg
来处理镜头。