#5590: "guarded instances": instance selection can add extra parameters to the
class
---------------------------------+------------------------------------------
Reporter: nfrisby | Owner:
Type: feature request | Status: new
Priority: normal | Component: Compiler (Type checker)
Version: 7.2.1 | Keywords:
Testcase: | Blockedby:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Comment(by nfrisby):
In case more motivation is needed; this example is one I find particularly
compelling,
[http://hackage.haskell.org/packages/archive/TypeCompose/0.8.3/doc/html
/Control-Compose.html#g:4 Conal Elliott's TypeCompose]. With just the
semantically-conservative extension:
{{{
data Pos; data Neg; type family Polarity (f :: * -> *)
instance guard Functor (g :. f) | Polarity g, Polarity f
instance ( Functor g, Functor f) => Functor (g :. f) | Pos, Pos where
fmap = fmapFF
instance (Cofunctor g, Cofunctor f) => Functor (g :. f) | Neg, Neg where
fmap = fmapCC
}}}
This also the AdvancedOverlap stuff. With that extra power, we can be more
direct.
{{{
instance guard Functor (g :. f) | (Functor f, Functor g) (Cofunctor f,
Cofunctor g)
-- NB some *->* can satisfy both Functor and Cofunctor
instance Functor (g :. f) | True co where fmap = fmapFF
instance Functor (g :. f) | False True where fmap = fmapCC
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5590#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs