title: Best way to apply arguments of mixed, possibly Applicative, types to a function
body: <p>I'm fairly new to Haskell and functional programming and I have recently been learning about Functors, Applicatives and Monads. While I seem to understand the basics, I have trouble figuring out the best/most idiomatic way apply function arguments when the type of some arguments changes to an Applicative. Consider the following, simple code:</p>
  
  <pre><code>myfun :: Int -&gt; Int -&gt; Int -&gt; Int
  myfun a b c = a + b + c             -- lets pretend this does something more complicated
  
  a = 5
  b = 10
  c = 20
  
  result = myfun a b c
  </code></pre>
  
  <p>Using <code>myfun</code> to calculate the result is fairly straightforward. However, as our requirements change, our inputs <code>a</code>, <code>b</code> and <code>c</code> may change to be i.e. <code>Maybe Int</code> or <code>[Int]</code> rather then <code>Int</code>. We can still use our unmodified <code>myfun</code> by doing one of the following:</p>
  
  <pre><code>result = myfun &lt;$&gt; a &lt;*&gt; b &lt;*&gt; c   -- either like this
  result = liftA3 myfun a b c        -- or like that
  </code></pre>
  
  <p>However, in practice the arguments <code>a</code>, <code>b</code> and <code>c</code> may not always end up to be inside the same Applicative, and thus the two methods mentioned above would not work. What is the best way to still make the <code>myfun</code> function work without modifying it? Consider the following scenarios for <code>a</code>, <code>b</code> and <code>c</code>:</p>
  
  <ul>
  <li>Some are <code>Int</code>, some are <code>Maybe Int</code> (result of the application would be <code>Maybe Int</code>)</li>
  <li>Some are <code>Maybe Int</code>, some are <code>Either String Int</code> (result could be <code>Maybe Int</code> or <code>Either String Int</code>, with the semantics of short-circuiting the calculation if any argument is <code>Nothing</code> or <code>Left</code>)</li>
  <li>Some are <code>[Int]</code>, some are <code>Maybe Int</code> (result should be <code>Maybe [Int]</code>, with the semantics of calculating all possible combinations as if all arguments were <code>[Int]</code>, then wrapping that inside a <code>Just</code>, unless on of the Maybies are <code>Nothing</code>, in which case we short-circuit to <code>Nothing</code>)</li>
  </ul>
  
  <p>Any insights are very much appreciated!</p>