title: What would be the type signature of a function that can be applied both like (& f %~) and (^. f) where operators are from Lens library?
body: <p>I have a function that gets a value from a record and sets it to the same field in a different record.</p>
  
  <p>What I want to do is understand how the mechanisms behind it works</p>
  
  <pre><code>setToPercent perc basedOn toSetOn = setStat
      where baseStat = basedOn ^. _func -- type is Maybe Float
            percentDelta = (\a -&gt; perc * a) &lt;$&gt; baseStat -- Maybe Float
            setStat = toSetOn &amp; _func %~ (\a -&gt; (+) &lt;$&gt; a &lt;*&gt; percentDelta)
  </code></pre>
  
  <p>Where <code>_func</code> is defined as <code>MyDataType -&gt; Maybe Float</code> (default function from record syntax.)</p>
  
  <p>And it works just like I expect it to. What I want to know is <code>_func</code>'s type signature.</p>
  
  <p>I know here <code>basedOn ^. _func</code>, <code>_func</code> would have the type 
  <code>Getting (f0 Float) MyDataType (f0 Float)</code></p>
  
  <p>and here <code>toSetOn &amp; _func %~ (\a -&gt; (+) &lt;$&gt; a &lt;*&gt; percentDelta</code>, <code>_func</code> would have the type <code>ASetter Weapon Weapon (f0 Float) (f0 Float)</code>
  where data <code>Weapon</code> and <code>MyDataType</code> are basically the same data type with identical constructors.</p>
  
  <p>But I'm not sure what would be the overall type.
  As in what would be the function type if I were to generalize <code>setToPercent</code> w.r.t <code>_func</code> as in</p>
  
  <pre><code>setToPercent fnToApply perc basedOn toSetOn = setStat
      where baseStat = basedOn ^. fnToApply -- type is Maybe Float
            percentDelta = (\a -&gt; perc * a) &lt;$&gt; baseStat -- Maybe Float
            setStat = toSetOn &amp; fnToApply %~ (\a -&gt; (+) &lt;$&gt; a &lt;*&gt; percentDelta)
  </code></pre>