
#16194: deriving, wrong code: newtype T cat a = MkT ((forall xx. cat xx xx) -> a) deriving stock Functor -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.7 Keywords: DeriveFunctor | Operating System: Unknown/Multiple deriving RankNTypes | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- This fails (`deriving stock Functor`) (data type comes from [https://duplode.github.io/extras/applicative-archery-manuscript.pdf Applicative Archery]) {{{ $ ./ghc-stage2 --interactive -ignore-dot-ghci GHCi, version 8.7.20181230: https://www.haskell.org/ghc/ :? for help Prelude> :set prompt "> "
:set -XRankNTypes -XDeriveFunctor -ddump-deriv :set -dsuppress-idinfo -dsuppress-coercions -dsuppress-type-applications -dsuppress-uniques -dsuppress-module-prefixes newtype T cat a = MkT ((forall xx. cat xx xx) -> a) deriving Functor
==================== Derived instances ==================== Derived class instances: instance Functor (T cat) where fmap f (MkT a1) = MkT ((\ b2 b3 -> f (b2 ((\ b1 -> b1) b3))) a1) (<$) z (MkT a1) = MkT ((\ b3 b4 -> (\ b2 -> z) (b3 ((\ b1 -> b1) b4))) a1) Derived type family instances: <interactive>:4:62: error: • Couldn't match type ‘forall xx. cat xx xx’ with ‘cat xx0 xx0’ Expected type: cat xx0 xx0 -> a Actual type: (forall xx. cat xx xx) -> a • In the first argument of ‘\ b2 b3 -> f (b2 ((\ b1 -> b1) b3))’, namely ‘a1’ In the first argument of ‘MkT’, namely ‘((\ b2 b3 -> f (b2 ((\ b1 -> b1) b3))) a1)’ In the expression: MkT ((\ b2 b3 -> f (b2 ((\ b1 -> b1) b3))) a1) When typechecking the code for ‘fmap’ in a derived instance for ‘Functor (T cat)’: To see the code I am typechecking, use -ddump-deriv • Relevant bindings include a1 :: (forall xx. cat xx xx) -> a (bound at <interactive>:4:62) fmap :: (a -> b) -> T cat a -> T cat b (bound at <interactive>:4:62) <interactive>:4:62: error: • Couldn't match type ‘forall xx. cat xx xx’ with ‘cat xx1 xx1’ Expected type: cat xx1 xx1 -> b Actual type: (forall xx. cat xx xx) -> b • In the first argument of ‘\ b3 b4 -> (\ b2 -> z) (b3 ((\ b1 -> b1) b4))’, namely ‘a1’ In the first argument of ‘MkT’, namely ‘((\ b3 b4 -> (\ b2 -> z) (b3 ((\ b1 -> b1) b4))) a1)’ In the expression: MkT ((\ b3 b4 -> (\ b2 -> z) (b3 ((\ b1 -> b1) b4))) a1) When typechecking the code for ‘<$’ in a derived instance for ‘Functor (T cat)’: To see the code I am typechecking, use -ddump-deriv • Relevant bindings include a1 :: (forall xx. cat xx xx) -> b (bound at <interactive>:4:62) (<$) :: a -> T cat b -> T cat a (bound at <interactive>:4:62)
}}} Generates odd code {{{#!hs fmap .. = MkT ((\ b2 b3 -> f (b2 ((\ b1 -> b1) b3))) a1) }}} It works fine (in HEAD) to `deriving newtype Functor` (it didn't in 8.2 where I checked) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16194 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler