我目前已经定义了两个函数:
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
来处理镜头。