4

weightDelta函数上运行 hlint 时,会不断提示 Eta reduce。我阅读了另一个相关的 Eta reduce question,但我似乎无法将理解转移到这个案例中。

module StackQuestion where

import qualified Data.Vector as V

type Weights = V.Vector Double
type LearningRate = Double

weightDelta :: LearningRate -> Double -> Double -> Weights -> Weights
weightDelta n r y ws = V.map update  ws
        where update w = diff * n * w
              diff = r - y

我试图“减少”它以指向自由语法的每一次更改都会破坏它。要在哪里进行更改,是否有任何直觉或技巧可以避免将来出现 eta reduce 建议?

4

1 回答 1

8

你不会轻易得到点语法,但你可以立即做的只是 η-reduce the wsaway。

weightDelta :: LearningRate -> Double -> Double -> Weights -> Weights
weightDelta n r y = V.map update
        where update w = diff * n * w
              diff = r - y

你也可以做类似的事情

        where update = (δ *)
              δ = n * (r - y)

但这是相当有争议的。

于 2012-07-08T08:56:00.863 回答