<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks David.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 13 Oct 2017, at 20:13, David McBride <<a href="mailto:toad3k@gmail.com" class="">toad3k@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">If you are using do notation, you can't. If you aren't you can write<br class=""><br class=""></div>tupled s = (rev s, cap s)<br class=""><br class=""></div>Your old tupled is equivalent to this<br class=""><br class=""></div>tupled = rev >>= \s -> cap >>= \c -> return (s, c)<br class=""><br class=""></div>which is quite different.<br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Oct 13, 2017 at 3:05 PM, mike h <span dir="ltr" class=""><<a href="mailto:mike_k_houghton@yahoo.co.uk" target="_blank" class="">mike_k_houghton@yahoo.co.uk</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 ..8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">That certainly helps me David, thanks.<div class="">How then would you write</div><div class=""><span class=""><blockquote type="cite" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">tupled :: String -> (String, String)</blockquote></div></div></blockquote><br class=""><div class=""> </div></span><div class="">with the parameter written explicitly? i.e.</div><div class=""><br class=""></div><div class="">tupled s = do …</div><div class=""><br class=""></div><div class="">or does the question not make sense in light of your earlier reply?</div><div class=""><br class=""></div><div class="">Thanks</div><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Mike</div></font></span><div class=""><div class="h5"><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 13 Oct 2017, at 19:35, David McBride <<a href="mailto:toad3k@gmail.com" target="_blank" class="">toad3k@gmail.com</a>> wrote:</div><br class="m_5963109587127880927Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class="">Functions are Monads.<br class=""><br class=""></div>:i Monad<br class="">class Applicative m => Monad (m :: * -> *) where<br class=""> (>>=) :: m a -> (a -> m b) -> m b<br class=""> (>>) :: m a -> m b -> m b<br class=""> return :: a -> m a<br class="">...<br class="">instance Monad (Either e) -- Defined in ‘Data.Either’<br class="">instance Monad [] -- Defined in ‘GHC.Base’<br class="">...<br class="">instance Monad ((->) r) -- Defined in ‘GHC.Base’<br class=""><br class=""></div>That last instance means if I have a function whose first argument is type r, that is a monad. And if you fill in the types of the various monad functions you would get something like this<br class=""><br class=""></div>(>>=) :: ((->) r) a -> (a -> ((-> r) b) -> ((-> r) b)<br class=""></div>(>>=) :: (r -> a) -> (a -> (r -> b)) -> (r -> b) -- simplified<br class=""></div><div class="">return :: a -> (r -> a)<br class=""><br class=""></div><div class="">So in the same way that (IO String) is a Monad and can use do notation, (a -> String) is also a Monad, and can also use do notation. Hopefully that made sense.<br class=""></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Oct 13, 2017 at 2:15 PM, mike h <span dir="ltr" class=""><<a href="mailto:mike_k_houghton@yahoo.co.uk" target="_blank" class="">mike_k_houghton@yahoo.co.uk</a>></span> wrote:<br class=""><blockquote class="gmail_quote"><br class="">
I have<br class="">
<br class="">
cap :: String -> String<br class="">
cap = toUpper<br class="">
<br class="">
rev :: String -> String<br class="">
rev = reverse<br class="">
<br class="">
then I make<br class="">
<br class="">
tupled :: String -> (String, String)<br class="">
tupled = do<br class="">
r <- rev<br class="">
c <- cap<br class="">
return (r, c)<br class="">
<br class="">
and to be honest, yes it’s been a long day at work, and this is coding at home rather than coding (java) at work but<br class="">
I’m not sure how tupled works!!!<br class="">
My first shot was supplying a param s like this<br class="">
<br class="">
tupled :: String -> (String, String)<br class="">
tupled s = do<br class="">
r <- rev s<br class="">
c <- cap s<br class="">
return (r, c)<br class="">
<br class="">
which doesn’t compile. But how does the first version work? How does the string to be processed get into the rev and cap functions??<br class="">
<br class="">
Thanks<br class="">
<br class="">
Mike<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
Beginners mailing list<br class="">
<a href="mailto:Beginners@haskell.org" target="_blank" class="">Beginners@haskell.org</a><br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-bi<wbr class="">n/mailman/listinfo/beginners</a><br class="">
</blockquote></div><br class=""></div>
______________________________<wbr class="">_________________<br class="">Beginners mailing list<br class=""><a href="mailto:Beginners@haskell.org" target="_blank" class="">Beginners@haskell.org</a><br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/beginners</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></div><br class="">______________________________<wbr class="">_________________<br class="">
Beginners mailing list<br class="">
<a href="mailto:Beginners@haskell.org" class="">Beginners@haskell.org</a><br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/beginners</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">Beginners mailing list<br class=""><a href="mailto:Beginners@haskell.org" class="">Beginners@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br class=""></div></blockquote></div><br class=""></div></body></html>