Compiler can't deduce Bool as instance of ToField

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?

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"
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@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (2)
-
Bryan Vicknair
-
Oliver Charles