title: Implementing liftM2 in Haskell
body: <p>For an exercise, I've been trying to implement liftM2 using just the functions ap and liftM. The functions are defined as:</p>
  
  <pre><code>ap :: IO (a -&gt; b) -&gt; IO a -&gt; IO b
  liftM :: (a -&gt; b) -&gt; IO a -&gt; IO b
  
  liftM2 :: (a -&gt; b -&gt; c) -&gt; IO a -&gt; IO b -&gt; IO c
  </code></pre>
  
  <p>I can easily do liftM2 using do notation but not sure how to do it using just ap and liftM. I was thinking of having the result be something that looks like this:</p>
  
  <pre><code>liftM2 f a b = liftM (_) (ap _ a)
  </code></pre>
  
  <p>I'm confused on how to mess with f, which is (a -> b -> c) such that I can just turn a to b and b to c. Thank you.</p>