| 9 | |
| 10 | === Implicit kind variable changes |
| 11 | |
| 12 | GHC 8.10 implements [https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0024-no-kind-vars.rst proposal 24], which means that GHC is much less likely to implicitly quantify kind variables than it used to be. Here are some examples of code which will no longer work with GHC 8.10: |
| 13 | |
| 14 | * Kind variables are no longer implicitly quantified when an explicit `forall` is used at the beginning of a function's type signature. For instance, the following will no longer work: |
| 15 | |
| 16 | {{{#!hs |
| 17 | {-# LANGUAGE PolyKinds #-} |
| 18 | {-# LANGUAGE ScopedTypeVariables #-} |
| 19 | |
| 20 | f :: forall (a :: k). Proxy a |
| 21 | f = Proxy |
| 22 | }}} |
| 23 | {{{ |
| 24 | error: Not in scope: type variable ‘k’ |
| 25 | | |
| 26 | 6 | f :: forall (a :: k). Proxy a |
| 27 | | ^ |
| 28 | }}} |
| 29 | |
| 30 | This is because `k` is implicitly quantified in the kind of `a`. Here are two potential ways to migrate this code: |
| 31 | |
| 32 | 1. If you are using GHC 8.0 or later, you can simply quantify `k` explicitly: |
| 33 | |
| 34 | {{{#!hs |
| 35 | f :: forall k (a :: k). Proxy a |
| 36 | f = Proxy |
| 37 | }}} |
| 38 | |
| 39 | Note that GHC 8.0, 8.2, and 8.4 require enabling the `TypeInType` extension in order to do this. On GHC 8.6 or later, however, explicitly quantifying kind variables simply requires the `PolyKinds` extension. |
| 40 | 2. If you need to support versions of GHC older than 8.0, you may find the following piece of `CPP` useful: |
| 41 | |
| 42 | {{{#!hs |
| 43 | #if __GLASGOW_HASKELL__ >= 800 |
| 44 | # define KVS(kvs) kvs |
| 45 | #else |
| 46 | # define KVS(kvs) |
| 47 | #endif |
| 48 | |
| 49 | f :: forall KVS(k) (a :: k). Proxy a |
| 50 | f = Proxy |
| 51 | }}} |
| 52 | * Kind variables are no longer implicitly quantified in data constructor declarations: |
| 53 | |
| 54 | {{{#!hs |
| 55 | data T a = T1 (S (a :: k) | forall (b::k). T2 (S b) -- no longer accepted |
| 56 | data T (a :: k) = T1 (S (a :: k) | forall (b::k). T2 (S b) -- still accepted |
| 57 | }}} |
| 58 | |
| 59 | As the above examples show, code that breaks because of this change can generally be fixed by adding explicit kind signatures to the type variable binders of the data type itself. |
| 60 | |
| 61 | * Implicitly quantified kind variables are no longer put in front of other variables: |
| 62 | |
| 63 | {{{#!hs |
| 64 | f :: Proxy (a :: k) -> Proxy (b :: j) |
| 65 | }}} |
| 66 | {{{ |
| 67 | ghci> :t +v f -- old order: |
| 68 | f :: forall k j (a :: k) (b :: j). Proxy a -> Proxy b |
| 69 | |
| 70 | ghci> :t +v f -- new order: |
| 71 | f :: forall k (a :: k) j (b :: j). Proxy a -> Proxy b |
| 72 | }}} |
| 73 | |
| 74 | This is a breaking change for users of `TypeApplications`. If you wish to restore the old order, then explicitly quantify the type variables: |
| 75 | * In type synonyms and type family equations, free variables on the right-hand side are no longer implicitly quantified unless used in an //outermost// kind annotation: |
| 76 | |
| 77 | {{{#!hs |
| 78 | type T = Just (Nothing :: Maybe a) -- no longer accepted |
| 79 | type T = Just Nothing :: Maybe (Maybe a) -- still accepted |
| 80 | }}} |