<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On 2008 Sep 24, at 22:51, Daryoush Mehrtash wrote:</div><blockquote type="cite"><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><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 "m" in:<br> <br>&nbsp;&nbsp;&nbsp;&nbsp; return (:) 'ap' c<br><br>"c" is obviously an&nbsp; instance of IO a monad.&nbsp;&nbsp; "return (:)"&nbsp; on the other hand (at least as I would expect it) is an instance of " ->" monad.&nbsp; <br></div></div></blockquote><div><br></div><div>Note that he first argument to ap is a function wrapped by a monad. &nbsp;"return (:)" wraps the function/operator (:) in an arbitrary monad (but then the type signature of sequence makes the monad IO).</div><div><br></div><div>&nbsp;&nbsp; &nbsp;(:) :: a -> [a] -> [a]</div><div>&nbsp;&nbsp; &nbsp;return (:) :: IO (a -> ([a] -> [a])) -- b is ([a] -> [a])</div><div>&nbsp;&nbsp; &nbsp;ap (return (:)) :: IO a -> IO ([a] -> [a]) -- (IO a) is (m a) and (IO ([a] -> [a])) is (m b)</div><div>&nbsp;&nbsp; &nbsp;return (:) `ap` c :: IO ([a] -> [a]) -- c is (IO a) per type signature</div><div>&nbsp;&nbsp; &nbsp;return (:) `ap` c `ap` :: IO [a] -> IO [a] -- f in ap is the preceding IO ([a] -> [a])</div><div>&nbsp;&nbsp; &nbsp;return (:) `ap` c `ap` sequence cs :: IO [a] -- (sequence cs) is (IO [a]) per type signature</div><div><br></div></div><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div><font class="Apple-style-span" face="Monaco"><span class="Apple-style-span" style="font-family: Monaco; "><span class="Apple-style-span" style="font-family: Monaco; ">--&nbsp;</span></span></font></div><div><font class="Apple-style-span" face="Monaco"><span class="Apple-style-span" style="font-family: Monaco; "><span class="Apple-style-span" style="font-family: Monaco; ">brandon s. allbery [solaris,freebsd,perl,pugs,haskell] <a href="mailto:allbery@kf8nh.com">allbery@kf8nh.com</a></span></span></font></div><div><font class="Apple-style-span" face="Monaco"><span class="Apple-style-span" style="font-family: Monaco; "><span class="Apple-style-span" style="font-family: Monaco; ">system administrator [openafs,heimdal,too many hats] <a href="mailto:allbery@ece.cmu.edu">allbery@ece.cmu.edu</a></span></span></font></div><div><font class="Apple-style-span" face="Monaco"><span class="Apple-style-span" style="font-family: Monaco; "><span class="Apple-style-span" style="font-family: Monaco; ">electrical and computer engineering, carnegie mellon university &nbsp; &nbsp;KF8NH</span></span></font></div><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><br class="Apple-interchange-newline"></span></span></span></div></span> </div><br></body></html>