[web-devel] Ambiguous type variable `mo0' in the constraint + Understanding how Widgets work
Mathew de Detrich
deteego at gmail.com
Sat Apr 30 11:11:10 CEST 2011
I am having issues figuring out how exactly widgets work within Yesod,
having a look at the example here
http://www.yesodweb.com/book/example-widgets
<http://www.yesodweb.com/book/example-widgets>There is an example
getHomeR = defaultLayout $ do
setTitle "Polymorphic Hamlet"
addHtml [$hamlet|<p>I was added with addHtml|]
addHamlet [$hamlet|<p>I was added with addHamlet|]
addWidget [$hamlet|<p>I was added with addWidget|]
Now assuming you have a Homer router set up, if you compile the example you
get Ambiguous type variable `mo0' in the constraint: (or errors of that
form). Asking on haskell irc, I found out this error is due to Haskell not
knowing what type Hamlet returns, which is probably the reason for this
comment
"However, there is a more subtle point as well. While in theory a Hamlet
template is polymorphic, this actually depends upon what values are embedded
inside it (using ^{...} interpolation). For example, [$hamlet|^{someValue}|]
will have the same type as someValue; if someValue is of type Hamlet, then
so will the template."
I assume that you are meant to have one ^{...} interpolation for every GET
route request you are attempting to do, so checking the example code
here here http://www.yesodweb.com/book/example-widgets, as I suspected
the variable interpolation is used in the root handler and in the form
handler (in the case for root handler it goes through a wrapper function).
The issue is, when I attempt to use the ^{...} interpolation in my code (in
this case I am literally just copying the wrapper function and passing it
through with defaultLayout $ wrapper $ do as with the example) I am still
getting the ambiguous type variable using this simple example
getIndexR = defaultLayout $ wrapper $ do
setTitle "Polymorphic Hamlet"
addHtml [$hamlet|<p>I was added with addHtml|]
addHamlet [$hamlet|<p>I was added with addHamlet|]
addWidget [$hamlet|<p>I was added with addWidget|]
Am I missing something fundamental here, because I am at odds of what to do
at this point (I am using yesod 7.0.3 if that matters). Also is there a non
trivial example of how combinating widgets is done to form a combined web
page (containing CSS, HTML and JS), i.e. whats mentioned here
"The job of a widget is to hold onto these disparate components and apply
proper logic for combining different widgets together. This consists of
things like taking the first title set and ignoring others, applying nub to
the list of external scripts and stylesheets, and simply concatenating head
and body content."
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110430/b770b585/attachment.htm>
More information about the web-devel
mailing list