[Haskell-cafe] Re: Small displeasure with associated type synonyms
Tom Schrijvers
Tom.Schrijvers at cs.kuleuven.be
Thu Mar 6 14:14:55 EST 2008
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: tom.schrijvers at cs.kuleuven.be
url: http://www.cs.kuleuven.be/~toms/
More information about the Haskell-Cafe
mailing list