[Haskell-beginners] do-notation question
es at ertes.de
Sat May 14 18:41:36 CEST 2011
blackcat at pro-ns.net wrote:
> In The Yesod Book, I see the following code:
> defaultLayout contents = do
> PageContent title headTags bodyTags <- widgetToPageContent $ do
> addCassius ...
> How does this work? Is bodyTags drawn from widgetToPageContent and
> then used as the third argument to PageContent?
This is just a regular pattern match, just like any of these:
x <- someComp
(x, y) <- someTupleComp
Just x <- someMaybeComp
[x, y, z] <- someListComp
x : y : _ <- someListComp
PageContent title headTags bodyTags <- somePageContentComp
someFunc (PageContent title headTags bodyTags) = ...
someFunc (Just x) = ...
What may confuse you is that PageContent is used in prefix notation
without any parentheses, whereas the usual constructors used in pattern
matching are written in infix or special syntax notation.
nightmare = unsafePerformIO (getWrongWife >>= sex)
More information about the Beginners