Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding of Eta reduce

When running hlint over the weightDelta function is keeps suggesting Eta reduce. I read another related Eta reduce question, but I can't seem to transfer the understanding into this case.

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

Every change I try to make to "reduce" it to point free syntax just breaks it. Where's the change to be made, and is there any sort of intuition or trick to avoid an eta reduce suggestion in the future?

like image 770
enjoylife Avatar asked Feb 19 '23 22:02

enjoylife


1 Answers

You won't get it to point- free syntax easily, but what you can do immediately is just η-reduce the ws away.

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

You can also do something like

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

but that's rather debatable.

like image 53
leftaroundabout Avatar answered Feb 27 '23 10:02

leftaroundabout