GHC: Ticket Query
http://ghc.haskell.org/trac/ghc/query?status=!closed&cc=~dreixel&order=priority
The Glasgow Haskell Compileren-USGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/query?status=!closed&cc=~dreixel&order=priority
Trac 1.0.1
http://ghc.haskell.org/trac/ghc/ticket/7908
http://ghc.haskell.org/trac/ghc/ticket/7908#7908: InstanceSigs suggestion not acceptedTue, 14 May 2013 10:46:00 GMTheisenbug<p>
Attached testcase compiles, but when
uncommenting either of the lines 19, 21 or 23,
I get an error:
</p>
<pre class="wiki">pr7908.hs:23:12:
Method signature does not match class; it should be
(>>-) :: forall (c :: k -> *) d.
Hidden k c -> (forall (a :: k). c a -> d) -> d
In the instance declaration for `Monad' k (Hidden k)'
Failed, modules loaded: none.
</pre><p>
But in fact I basically copied the suggestion into my file! (with slight modification "Hidden k c" --> "Hidden c")
</p>
<p>
This may be because of the rank2 type or because of the polykinds appearing.
</p>
Resultshttp://ghc.haskell.org/trac/ghc/ticket/7908#changelog
http://ghc.haskell.org/trac/ghc/ticket/8516
http://ghc.haskell.org/trac/ghc/ticket/8516#8516: Add (->) representation and the Invariant class to GHC.GenericsSat, 09 Nov 2013 20:39:41 GMTnfrisby<p>
We currently disallow any use of the parameter in the domain of (->).
</p>
<pre class="wiki">newtype F a = F ((a -> Int) -> Int) deriving Generic1
<interactive>:4:38:
Can't make a derived instance of `Generic1 (F g)':
Constructor `F' must use the last type parameter only as the last argument of a data type, newtype, or (->)
In the data declaration for `F'
</pre><p>
DeriveFunctor succeeds for this F.
</p>
<p>
I'd like to add this representation type to GHC.Generics and DeriveGeneric.
</p>
<pre class="wiki">newtype (f :->: g) a = FArrow1 (f a -> g a)
</pre><p>
We could then represent the first example above. We could also derive the more interesting Generic1 (F g).
</p>
<pre class="wiki">newtype F g a = F (g a -> Int) deriving Generic1
type instance Rep1 (F g) = Rec1 g :->: Rec0 Int
instance Generic1 (F g) where
to x = F $ unRec0 . unArrow1 x . Rec1
from (F x) = FArrow1 $ Rec0 . x . unRec1
</pre><p>
Admittedly, there's not many generic definitions impeded by not having (:->:). Contra- and in-variant types are uncommon.
</p>
<p>
I'm suggesting this feature without strong motivating examples because I think this would streamline the implementation of -XDeriveGenerics in some ways while also making it more general — assuming that we added the Invariant class to base or ghc-prim.
</p>
<pre class="wiki">class Invariant t where
invmap :: (a -> b) -> (b -> a) -> t a -> t b
invmap_covariant :: Functor t => (a -> b) -> (b -> a) -> t a -> t b
invmap_covariant f _ = fmap f
instance (Invariant f,Invariant g) => Invariant (FArrow f g) where
invmap co contra (FArrow h) = FArrow $ invmap co contra . h . invmap contra co
</pre><p>
(Of course, Invariant should be a super class of Functor. :/ )
</p>
<p>
Now we can handle quite involved examples:
</p>
<pre class="wiki">newtype F g h a = F (g (h a)) deriving Generic1
instance Invariant g => Generic1 (F g h) where
to x = invmap unRec1 Rec1 $ unComp1 x
from (F x) = Comp1 $ invmap Rec1 unRec1
</pre><p>
All of that said, I'm mostly opening this ticket so I can get feedback on difficulties I might not be anticipating and have a place to reference from the compiler source code comments.
</p>
Resultshttp://ghc.haskell.org/trac/ghc/ticket/8516#changelog