[web-devel] Yesod question: renaming widget functions

Michael Snoyman michael at snoyman.com
Sun Oct 24 09:58:11 CEST 2010

Hey all,

I have a general rule of thumb: if I get confused about how I named
things, I probably named them badly. For example, addStyle takes a
Cassius value as an argument, while addStylesheet takes a route to a
CSS file. On the other hand, addScript takes a route to a Javascript
file, and addJavascript takes a Julius value. There's also addBody,
which takes a Hamlet.

And there's no addWidget, which is fine (it would just be id), except
that it looks wrong and can lead to confusing type errors with the new
polymorphic Hamlet. For example:

    defaultLayout $ do
        setTitle "Widget test"
        [$hamlet|This is a widget|]

works fine, but:

    defaultLayout $ do
        [$hamlet|This is a widget|]
        setTitle "Widget test"

confuses the compiler. I'm considering some renamings for Yesod 0.6
which will cause breakage, so I wanted your opinions if the changes
are worth it, or if you have any better ideas. Here's what I'm

addCassius :: Cassius -> Widget
addJulius :: Julius -> Widget
addHamlet :: Hamlet -> Widget
addHtml :: Html -> Widget
addHamletHead :: Hamlet -> Widget
addHtmlHead :: Html -> Widget
addWidget :: Widget -> Widget
addStylesheet :: Route -> Widget
addScript :: Route -> Widget

And with the new polymorphic hamlet, I don't think wrapWidget and
extractWidget are generally necessary. Nonetheless, I think I'd like
to leave extractWidget, in case there is some use case I'm not
thinking of. I think it's safe to remove wrapWidget, as it's easy to
express it in terms of extractWidget.



More information about the web-devel mailing list