
2014-10-02 16:21 GMT+02:00 Oleg
However, given
f2 :: Show a => a -> String f2 x = let instance Show Int where show _ = "one" in show x
what should (f2 (1::Int)) return?
I haven't studied this in detail (yet :)), but can't we solve this coherence problem by requiring a bit of additional type annotations from the programmer? Specifically, I would expect the problem to go away if we require the user to explicitly state the resulting type of the "let instance" expression. The syntax could look like let instance Show Int where show _ = "one" in show x as Show a => String where the specification "Show a => String" would imply that the Show a instance is propagated outwards and the Show Int instance is unused. If the programmer instead wrote let instance Show Int where show _ = "one" in show x as String That would imply that the compiler should try to resolve the required "Show a" constraint, but I would then expect an error saying that "Show a" cannot be derived from "Show Int", because we don't apply unification to constraints (or at least, GHC doesn't, and it seems like a good idea not to). Such an additional annotation is a bit more work for the programmer, but perhaps that might be acceptable for this indeed sorely missed feature? Regards, Dominique