[Haskell-cafe] Ambiguous types for collection keys

ihope ihope127 at gmail.com
Wed Apr 12 11:08:31 EDT 2006

On 4/12/06, Scott Weeks <weeksie at twelvestone.com> wrote:
> Hello everyone,
> I've been banging my head against my desk a bit so I figured it's time
> to ask for help :-)
> When a user queries I have to read the input from IO and then somehow
> cast the key/index type without angering the type checker. If I omit
> the following function I get the ominous "Ambiguous type variable a..."
> error. If I use it I get a complaint that the checker was expecting an
> Integer rather than a PackedString.

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.

More information about the Haskell-Cafe mailing list