[Haskell-beginners] Compiler can't deduce Bool as instance of ToField

Oliver Charles ollie at ocharles.org.uk
Wed Aug 14 14:16:49 CEST 2013


You have declared that foo is *any* type that has a ToField instance,
allowing the caller of foo to determine the type at their will. However,
your implementation of foo is more specific and requires a is actually Bool
and nothing else.
On 14 Aug 2013 10:24, "Bryan Vicknair" <bryanvick at gmail.com> wrote:

> postgresql-simple declares Bool as an instance of the ToField class.  The
> compiler can't deduce that given this simple code however:
>
>   import Database.PostgreSQL.Simple.ToField (ToField(..))
>
>   foo :: (ToField a) => a
>   foo = True
>
>
> It fails with this error:
>
>   Db.hs:64:7:
>       Could not deduce (a ~ Bool)
>       from the context (ToField a)
>         bound by the type signature for foo :: ToField a => a
>         at Db.hs:63:8-23
>         `a' is a rigid type variable bound by
>             the type signature for foo :: ToField a => a at Db.hs:63:8
>       In the expression: True
>       In an equation for `foo': foo = True
>   Failed, modules loaded: none.
>
> What am I missing?
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130814/ea16a81e/attachment.htm>


More information about the Beginners mailing list