了解Eta减少

enj*_*ife 4 haskell types ghc pointfree

当在weightDelta函数上运行hlint时,一直在暗示Eta减少.我读了另一个相关的Eta reduce 问题,但我似乎无法将理解转移到这个案例中.

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
Run Code Online (Sandbox Code Playgroud)

我试图"减少"它以指向免费语法的每一个改变都会破坏它.哪里有变化,是否有任何直觉或伎俩可以避免将来减少eta减少的建议?

lef*_*out 8

你不会轻易地得到点语法,但你可以立即做的只是η-减少了ws.

weightDelta :: LearningRate -> Double -> Double -> Weights -> Weights
weightDelta n r y = V.map update
        where update w = diff * n * w
              diff = r - y
Run Code Online (Sandbox Code Playgroud)

你也可以这样做

        where update = (? *)
              ? = n * (r - y)
Run Code Online (Sandbox Code Playgroud)

但这是值得商榷的.

  • 你也可以写`update =(n*(r - y)*)`. (3认同)