Stefan,

I tried lexically scoped type variables, but to no avail:

instance forall a b. (C a, C b) => C (a, b) where
  type T (a, b) = (T a, T b)
  val           = (val :: T a, val :: T b)

The problem is ambiguity. The type checker can't determine which val function to use, i.e. which dictionary to pass to val. Assume:

  instance C Int where
    type T Int = Int
    val        = 0

  instance C Bool where
    type T Bool = Int
    val         = 1

Now, if you want some val :: Int, which one do you get? The one of C Int of C Bool? Depending on the choice you may get a different result. We can't have that in a deterministic functional language. Hence the error.
Adding a type signature doesn't change the matter.

Providing an additional argument, as you propose, resolves the ambiguity.

I hope this helps.

Cheers,

Tom

--
Tom Schrijvers

Department of Computer Science
K.U. Leuven
Celestijnenlaan 200A
B-3001 Heverlee
Belgium

tel: +32 16 327544
e-mail: [EMAIL PROTECTED]
url: http://www.cs.kuleuven.be/~toms/
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to