[Haskell-cafe] [web-devel] Odd "Ambiguous type variable `a0' in the constraint:" error (with Yesod)

Michael Snoyman michael at snoyman.com
Sun May 1 15:00:46 CEST 2011

Without seeing the actual code that's causing the breakage, there's
not much I can tell you. (If you'd like me to take a look off-list,
feel free to send me a private email.) My best recommendation is to
try putting a type signature on getRootR.

As a general issue: polymorphic Hamlet is a very convenient feature,
but I think it leads to too much complexity in the type system. I've
added some code for non-polymorphic Hamlet to the Github repo and will
be releasing it as its own module (Text.Hamlet.NonPoly) in the next
release. Assuming all goes well, it will be replacing the current
Hamlet. That essentially means that you'll need to replace your code
with something like:

getRootR = defaultLayout $ do
    setTitle "Polymorphic Hamlet"
    addHtml [$html|<p>I was added with addHtml|]
    addHamlet [$hamlet|<p>I was added with addHamlet|]
    addWidget [$whamlet|<p>I was added with addWidget|]

And just to make everyone curious: I've also added i18n support to
non-poly Hamlet. I've got a long train ride on Tuesday, and I'm
planning on documenting it then.


On Sun, May 1, 2011 at 6:50 AM, Mathew de Detrich <deteego at gmail.com> wrote:
> Ok so I have a problem that was described here
> (http://permalink.gmane.org/gmane.comp.lang.haskell.web/1431) in regards to
> returning a  "Ambiguous type variable `a0' in the constraint error" when
> compiling. Originally I thought it was due to the way I was coding that part
> of the code (or to be more accurate the code specifically for creating the
> so called widgets with addHTML/addWidget,addHamlet). So I copied the example
> code given here exactly (http://www.yesodweb.com/book/example-widgets).
> Compiling this worked fine, so at the next point I changed the definition
> of 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|]
> and then to
> getRootR = 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|]
> Both times compiled fine, so the issue wasn't what I originally thought that
> it was (as described
> in http://permalink.gmane.org/gmane.comp.lang.haskell.web/1431). The problem
> is, that when I use the above example code in my WebServer, I get this
> Ambigious type error when compiling (even though I have set up the route the
> exact same way). Unfortunatley I can't provide the code for my webserver,
> since its commercially owned (and it would be pointless because its just
> renamed variables, but otherwise its the same), so does anyone have any
> ideas what could possibly cause such an error (such as a missing/extra
> import or some package or something), or possibly some missing instances?
> Also sorry for creating another mailing list, but its a different issue then
> what I thought it was originally (and I also wanted to put it on
> haskell-cafe since its a more general issue)
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel

More information about the Haskell-Cafe mailing list