26 Jul 2000 18:33:12 GMT, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> pisze:
> AAA! Thank you, it works now!
But there are problems with type inference. An example can be reduced
to that:
------------------------------------------------------------------------
module Class where
class FA f h where ca :: f -> h
instance FA [a] [a] where ca = id
test1:: [Int]
test1 = ca []
test2:: [a]
test2 = ca []
------------------------------------------------------------------------
Class.hs:7:
Ambiguous type variable(s) `t' in the constraint `FA [t] [Int]'
arising from use of `ca' at Class.hs:7
In the right-hand side of an equation for `test1': ca []
Class.hs:10:
Could not deduce `FA [t] [a]'
from the context ()
Probable fix:
Add `FA [t] [a]' to the type signature for `test2'
Or add an instance declaration for `FA [t] [a]'
arising from use of `ca' at Class.hs:10
In the right-hand side of an equation for `test2': ca []
------------------------------------------------------------------------
Am I right that what would help here is called "improvement"?
Almost. I think that even improvement would not help here: if
instance FA [Maybe a] [a]
existed, it could match too, so the calls are incorrect. The fact
that it does not exist does not matter :-(
These examples can be compiled by adding a type signature to [],
but in the real case it's quite big. Functional dependencies cannot
be used because other instances are not unique in any direction.
What I can't tell the compiler is "there will not be any other instances
FA [foo] [bar], so if you need one, you may assume that foo == bar".
BTW, the second error message does not give a good advice: I cannot add
`FA [t] [a]' to the context of the type signature for `test2' because
the type t does not exist there.
--
__("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
\__/ GCS/M d- s+:-- a23 C+++$ UL++>++++$ P+++ L++>++++$ E-
^^ W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK 5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-