Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top