[web-devel] Ambiguous type variable `mo0' in the constraint + Understanding how Widgets work

Mathew de Detrich deteego at gmail.com
Sun May 1 05:20:51 CEST 2011


Ok, it definitly seems like its an issue with the way I have yesod set up
(and nothing to do with the widget example I gave before).

Just blatantly copying the example here
http://www.yesodweb.com/book/example-widgets and messing around with it, it
always compiled fine, even when changing getRootR to
getRootR = 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|]

which compiles fun. This means that there must be something different in the
way I have set up routes (or something else) in my program (i was just
copying the examples into a temp route I created in my webserver)

Does anyone know what could be causing that error?

On Sat, Apr 30, 2011 at 7:11 PM, Mathew de Detrich <deteego at gmail.com>wrote:

> 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/20110501/39f99caf/attachment.htm>


More information about the web-devel mailing list