
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? tia, Lee

My guess is widgetToPageContent is a function that takes "do addCassius ..."
and returns a value in the monad "m T" where "T" is some datatype like "data
T = PageContent x y z | ..." . The "<-" removes the "m" from "m T" and
pattern matches "x", "y" and "z" to "title", "headTags" and "bodyTags".
-deech
On Fri, May 13, 2011 at 9:55 PM,
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?
tia, Lee
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

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?
I believe it's a pattern match; widgetToPageContent returns a PageContent (in some monad), which is bound to "PageContent title headTags bodyTags" -- so the three variables are bound to.
tia, Lee

blackcat@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 or: 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. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/
participants (4)
-
aditya siram
-
Arlen Cuss
-
blackcat@pro-ns.net
-
Ertugrul Soeylemez