
#9334: Implement "instance chains" -------------------------------------+------------------------------------- Reporter: diatchki | Owner: diatchki Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.9 Component: Compiler | Keywords: (Type checker) | Operating System: Unknown/Multiple Resolution: | Type of failure: None/Unknown Differential Revisions: | Test Case: Architecture: | Blocking: Unknown/Multiple | Difficulty: Unknown | Blocked By: | Related Tickets: | -------------------------------------+------------------------------------- Comment (by diatchki): Actually, there is no requirement that an instance chain be closed and, in fact, I was thinking of just starting with open ones. Of course, one could do the same sort of encoding using open TFs. However, the encoding does not fully subsume instance chains. For example, using instance chains I could write instances like these: {{{ instance Show (MyContainer Char) where ... else Show a => Show (MyContainer a) where ... }}} I couldn't do this with the encoding because the `Show` class does not have the extra parameter that would be needed. Not only is the encoding not pretty (imagine the type error you'd get for a missing instance), but using it requires enabling some fancy machinery (TFs, which pulls in FC, and reasoning about equality, etc.). Of course, we already have all this, but somehow it feels like implementing an easy idea, using some very advanced tools and, perhaps, it is better if we do not entangle these two. As for point (2), instance chains pretty much cover all the situations where ''I'' have wanted to use overlap (note the emphasis on ''I'' :-). For example, I wouldn't provide a global "default" instance, because it is too error prone. For the sake of concreteness, here is what I am referring to: {{{ class MyShow a where myShow :: a -> String -- default instance instance {-# OVERLAP #-} MyShow a where myShow _ = "(can't show this)" showInParens x = "(" ++ myShow x ++ ")" }}} In this example, `showInParens` would very likely not do what we intended, because it will commit to the "default" instance prematurely. Of course, this is just one example, but I think it is fairly representative of the difficulties inherent in using cross-module overlapping instances. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9334#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler