<div dir="ltr"><div><div><div><div><div><div>Functions are Monads.<br><br></div>:i Monad<br>class Applicative m => Monad (m :: * -> *) where<br>  (>>=) :: m a -> (a -> m b) -> m b<br>  (>>) :: m a -> m b -> m b<br>  return :: a -> m a<br>...<br>instance Monad (Either e) -- Defined in ‘Data.Either’<br>instance Monad [] -- Defined in ‘GHC.Base’<br>...<br>instance Monad ((->) r) -- Defined in ‘GHC.Base’<br><br></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><br></div>(>>=) :: ((->) r) a -> (a -> ((-> r) b) -> ((-> r) b)<br></div>(>>=) :: (r -> a) -> (a -> (r -> b)) -> (r -> b) -- simplified<br></div><div>return :: a -> (r -> a)<br><br></div><div>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></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 13, 2017 at 2:15 PM, mike h <span dir="ltr"><<a href="mailto:mike_k_houghton@yahoo.co.uk" target="_blank">mike_k_houghton@yahoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
I have<br>
<br>
cap :: String -> String<br>
cap = toUpper<br>
<br>
rev :: String -> String<br>
rev = reverse<br>
<br>
then I make<br>
<br>
tupled :: String -> (String, String)<br>
tupled = do<br>
    r <- rev<br>
    c <- cap<br>
    return (r, c)<br>
<br>
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>
I’m not sure how tupled  works!!!<br>
My first shot was supplying a param s like this<br>
<br>
tupled :: String -> (String, String)<br>
tupled s = do<br>
    r <- rev s<br>
    c <- cap s<br>
    return (r, c)<br>
<br>
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>
<br>
Thanks<br>
<br>
Mike<br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>