[GHC] #14131: Difference between newtype and newtype instance

GHC ghc-devs at haskell.org
Wed Aug 16 23:37:10 UTC 2017


#14131: Difference between newtype and newtype instance
-------------------------------------+-------------------------------------
           Reporter:  Iceland_jack   |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.2.1
           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:
-------------------------------------+-------------------------------------
 This works

 {{{#!hs
 {-# Language RankNTypes, PolyKinds, GADTs #-}

 newtype Nat :: (k -> *) -> (k -> *) -> * where
   Nat :: (forall xx. f xx -> g xx) -> Nat f g
 }}}

 but this

 {{{#!hs
 {-# Language RankNTypes, PolyKinds, GADTs, TypeFamilies #-}

 data family Nat :: k -> k -> *

 newtype instance Nat :: (k -> *) -> (k -> *) -> * where
   Nat :: (forall xx. f xx -> g xx) -> Nat f g
 }}}

 fails on GHC 8.3.20170815, and requires a `forall k.` to work

 {{{
 $ ./ghc-stage2 -ignore-dot-ghci --interactive /tmp/kind.hs
 GHCi, version 8.3.20170815: http://www.haskell.org/ghc/  :? for help
 [1 of 1] Compiling Main             ( /tmp/kind.hs, interpreted )

 /tmp/kind.hs:5:26: error: Not in scope: type variable ‘k’
   |
 5 | newtype instance Nat :: (k -> *) -> (k -> *) -> * where
   |                          ^

 /tmp/kind.hs:5:38: error: Not in scope: type variable ‘k’
   |
 5 | newtype instance Nat :: (k -> *) -> (k -> *) -> * where
   |                                      ^
 Failed, 0 modules loaded.
 }}}

 Related to #12369?

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14131>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list