[Haskell-cafe] Ambiguous types for collection keys

Scott Weeks weeksie at twelvestone.com
Wed Apr 12 15:18:47 EDT 2006

> Well, if you get an "ambiguous type variable" error, you probably (I
> think) need to add some type annotations. For example:
> class Foo a where
>   foo :: a
>   bar :: a -> String
> Evaluating bar foo will result in an error, but bar (foo :: Integer)
> will work just fine.
> ____________________

The problem is that I get  an incoming value which is a key of some 
sort. There's no way of knowing what type that value is supposed to be 
until I compare it with the schema from the above example. where I _am_ 
adding type annotations.

coerceIndex f (Schema _ SInt SPtr _) (r,hdl,o,hdr) = f 
coerceIndex f (Schema _ SStr SPtr _) (r,hdl,o,hdr) = f 

When I try to add type annotations I get a complaint from the 
typechecker that says (In the case of the above example) Expected type: 
Integer, Inferred Type: PackedString.

Is the alternative to write different "select" methods for each key 
type (selectInt, selectPS, ...)? God I hope not, that would be a bit 

More information about the Haskell-Cafe mailing list