[GHC] #15376: GHC determine illegal kind for standalone deriving with Deriving via

#15376: GHC determine illegal kind for standalone deriving with Deriving via -------------------------------------+------------------------------------- Reporter: | Owner: (none) mizunashi_mana | Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Happy to release GHC 8.6.1-alpha1! I used it to test new extensions, and then I met below errors: {{{ $ ghci-8.6.0.20180627 GHCi, version 8.6.0.20180627: http://www.haskell.org/ghc/ :? for help Prelude> :set -XDerivingVia -XStandaloneDeriving Prelude> newtype FunctorWrapped f a = FunctorWrapped (f a) Prelude> deriving via f instance Functor f => Functor (FunctorWrapped f) <interactive>:3:33: error: • Expected kind ‘* -> *’, but ‘f’ has kind ‘*’ • In the first argument of ‘Functor’, namely ‘f’ In the stand-alone deriving instance for ‘Functor f => Functor (FunctorWrapped f)’ <interactive>:3:62: error: • Expected kind ‘* -> *’, but ‘f’ has kind ‘*’ • In the first argument of ‘FunctorWrapped’, namely ‘f’ In the first argument of ‘Functor’, namely ‘(FunctorWrapped f)’ In the stand-alone deriving instance for ‘Functor f => Functor (FunctorWrapped f)’ }}} However, {{{ newtype FunctorWrapped f a = FunctorWrapped (f a) deriving Functor via f }}} is passed through on GHC 8.6.1-alpha1. Is this a bug or my misunderstand? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15376 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15376: GHC determine illegal kind for standalone deriving with Deriving via -------------------------------------+------------------------------------- Reporter: mizunashi_mana | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * keywords: => deriving * cc: Iceland_jack, RyanGlScott (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15376#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15376: GHC determine illegal kind for standalone deriving with Deriving via -------------------------------------+------------------------------------- Reporter: mizunashi_mana | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 14331 | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: kosmikus (added) * blockedby: => 14331 Comment: This is indeed a known limitation of the way `deriving` declarations are typechecked. //Short answer//: You can work around the issue by introducing an explicit type signature, i.e., {{{#!hs deriving via (f :: * -> *) instance Functor f => Functor (FunctorWrapped f) }}} //Long answer//: Any type variables quantified by `via` are kind-checked in isolation, without any information that might be gleaned from bidirectionally kind-checking the instance head. This means that GHC sees: {{{ deriving via f ... }}} And hastily concludes that `f` is of kind `*`. Bummer. We (kosmikus, Iceland_jack, and I) discussed this at some length in https://github.com/RyanGlScott/ghc/issues/29, and came to the conclusion that we might be able to fix this issue by introducing fresh unification variables when kind-checking, then unifying, and then generalizing/skolemizing if there are any unfilled unification variables left. This bears a close resemblance to the algorithm described in https://ghc.haskell.org/trac/ghc/ticket/14331#comment:31, so I'm going to claim that this ticket is blocked by #14331. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15376#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15376: GHC determine illegal kind for standalone deriving with Deriving via -------------------------------------+------------------------------------- Reporter: mizunashi_mana | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 14331 | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mizunashi_mana): Replying to [comment:2 RyanGlScott]:
This is indeed a known limitation of the way `deriving` declarations are typechecked.
I understand. Thank you for your comment. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15376#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC