<div dir="ltr">I am having hard time making sense of the types in the following example from the Applicative Programming paper: <a href="http://www.cs.nott.ac.uk/~ctm/IdiomLite.pdf">http://www.cs.nott.ac.uk/~ctm/IdiomLite.pdf</a><br>
<br><br><div><div style="margin-left: 40px;">ap :: Monad m $B"M(B m (a $B"*(B b ) $B"*(B m a $B"*(B m b <br>ap mf mx = do <br> &nbsp; &nbsp; f $B"+(B mf <br> &nbsp; &nbsp; x $B"+(B mx <br> &nbsp; &nbsp; return (f x ) <br></div>Using this function we could rewrite sequence as: <br>
<br><div style="margin-left: 40px;">sequence :: [ IO a ] $B"*(B IO [ a ] <br>sequence [ ] = return [ ] <br>sequence (c : cs ) =<b> return (:) 'ap' c </b>'ap' sequence cs <br><br></div><br>I am specifically confused over the type of &quot;m&quot; in:<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp; return (:) &#39;ap&#39; c<br><br>&quot;c&quot; is obviously an&nbsp; instance of IO a monad.&nbsp;&nbsp; &quot;return (:)&quot;&nbsp; on the other hand (at least as I would expect it) is an instance of &quot; -&gt;&quot; monad.&nbsp; <br>
<br>a) are the above statements correct?<br>b) if so, does it make sense for the &quot;ap&quot;&nbsp; function to have two different instances of the &quot;m&quot;?&nbsp;&nbsp;&nbsp; <br><br>thanks for you help<br><br>daryoush<br></div></div>