[Haskell-beginners] How to unnest "do"

Emmanuel Touzery etouzery at gmail.com
Sun Jan 27 21:46:30 CET 2013


Thank you. I thought it might be, but it isn't exactly intuitive for me at
this point. I'll read some more about that monad.
On 27 Jan 2013 21:35, "Brent Yorgey" <byorgey at seas.upenn.edu> wrote:

> On Sun, Jan 27, 2013 at 09:29:27PM +0100, Emmanuel Touzery wrote:
> > >     stats :: String -> String
> > >     stats =
> > >         unwords .
> > >         sequence [show . length . words,
> > >                   show . length . lines,
> > >                   show . length]
> > >
> > >
> > [..]
> >
> >
> > > This improves the statistics code slightly, but uses some monadic
> > > machinery you may not be familiar with.  Another way to read the
> 'stats'
> > > function is this:
> > >
> > >     stats :: String -> String
> > >     stats str =
> > >         unwords [show . length . words $ str,
> > >                  show . length . lines $ str,
> > >                  show . length $ str]
> > >
> >
> >
> > I'm sorry, may I ask on which monad here is "sequence" operating?
> >
> > I can see that sequence here turns [a->a] into a->[a], I'm just not sure
> > which is the monad at play here... I just need a little bit more
> > explanation about this code before I get it.
>
> It is the ((->) a)  monad, also known as the reader monad.
>
> -Brent
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130127/52823779/attachment-0001.htm>


More information about the Beginners mailing list