Update 8.6 authored by Ryan Scott's avatar Ryan Scott
[[_TOC_]]
# GHC 8.6.x Migration Guide # GHC 8.6.x Migration Guide
...@@ -14,18 +16,21 @@ As part of [this GHC proposal](https://github.com/ghc-proposals/ghc-proposals/bl ...@@ -14,18 +16,21 @@ As part of [this GHC proposal](https://github.com/ghc-proposals/ghc-proposals/bl
`StarIsType` is enabled by default, and one consequence of this is that GHC will interpret any use of `*` as `Type`, even if it would have been previously interpreted as a binary type operator. A notable example of such a binary type operator is `GHC.TypeLits.*`, so code like: `StarIsType` is enabled by default, and one consequence of this is that GHC will interpret any use of `*` as `Type`, even if it would have been previously interpreted as a binary type operator. A notable example of such a binary type operator is `GHC.TypeLits.*`, so code like:
``` ```hs
importGHC.TypeLitsf::Proxy m ->Proxy n ->Proxy(m * n)f__=Proxy import GHC.TypeLits
f :: Proxy m -> Proxy n -> Proxy (m * n)
f _ _ = Proxy
``` ```
Will not typecheck if `StarIsType` is enabled, since `m * n` is treated as if one had written `m Type n`. There are several ways to adapt to this: Will not typecheck if `StarIsType` is enabled, since `m * n` is treated as if one had written `m Type n`. There are several ways to adapt to this:
1. Use `*` qualified (e.g., `Proxy (m GHC.TypeLits.* n`). This approach is compliant with the GHC three-release policy, as it does not require CPP to support older GHCs. 1. Use `*` qualified (e.g., `Proxy (m GHC.TypeLits.* n`). This approach is compliant with the GHC three-release policy, as it does not require CPP to support older GHCs.
1. Enable the `NoStarIsType` extension using a `LANGUAGE` pragma. Since `(No)StarIsType` did not exist on older GHCs, this approach will require CPP in order to support older compilers. 2. Enable the `NoStarIsType` extension using a `LANGUAGE` pragma. Since `(No)StarIsType` did not exist on older GHCs, this approach will require CPP in order to support older compilers.
1. Conditionally enable the `NoStarIsType` extension using Cabal's `default-extensions` field, like this: 3. Conditionally enable the `NoStarIsType` extension using Cabal's `default-extensions` field, like this:
```wiki ```
if impl(ghc >= 8.6) if impl(ghc >= 8.6)
default-extensions: NoStarIsType default-extensions: NoStarIsType
``` ```
...@@ -35,18 +40,22 @@ Will not typecheck if `StarIsType` is enabled, since `m * n` is treated as if on ...@@ -35,18 +40,22 @@ Will not typecheck if `StarIsType` is enabled, since `m * n` is treated as if on
GHC now enables the `MonadFailDesugaring` extension by default, as discussed in [https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail\#Transitionalstrategy](https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail#Transitionalstrategy). This means that code that uses partial pattern matches in `do`-notation, such as this: GHC now enables the `MonadFailDesugaring` extension by default, as discussed in [https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail\#Transitionalstrategy](https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail#Transitionalstrategy). This means that code that uses partial pattern matches in `do`-notation, such as this:
``` ```hs
f::[[a]]->[a]f l =do(_:xs)<- l f :: [[a]] -> [a]
f l = do
(_:xs) <- l
xs xs
``` ```
Will now desugar to use the `fail` method from the `MonadFail` class instead of from `Monad`. That is, this code will now desugar to something resembling: Will now desugar to use the `fail` method from the `MonadFail` class instead of from `Monad`. That is, this code will now desugar to something resembling:
``` ```hs
import Control.Monad.Fail as Fail import Control.Monad.Fail as Fail
f::[[a]]->[a]f l =case l of(_:xs)-> xs f :: [[a]] -> [a]
f l = case l of
(_:xs) -> xs
_ -> Fail.fail "Pattern-match failure" _ -> Fail.fail "Pattern-match failure"
``` ```
...@@ -63,14 +72,15 @@ Data types with empty `where` clauses (such as `data T where`) are no longer val ...@@ -63,14 +72,15 @@ Data types with empty `where` clauses (such as `data T where`) are no longer val
Due to a bug, previous versions of GHC would not emit any `-Wincomplete-patterns` warnings at all for incomplete patterns inside of guards or `MultiWayIf` expressions. This bug has been fixed, which means that code like: Due to a bug, previous versions of GHC would not emit any `-Wincomplete-patterns` warnings at all for incomplete patterns inside of guards or `MultiWayIf` expressions. This bug has been fixed, which means that code like:
``` ```hs
foo::Bool->Intfoo b =if| b ->1 foo :: Bool -> Int
foo b = if | b -> 1
``` ```
Will now raise a warning in GHC 8.6: Will now raise a warning in GHC 8.6:
```wiki ```
warning: [-Wincomplete-patterns] warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive Pattern match(es) are non-exhaustive
In a multi-way if alternative: In a multi-way if alternative:
...@@ -82,7 +92,7 @@ warning: [-Wincomplete-patterns] ...@@ -82,7 +92,7 @@ warning: [-Wincomplete-patterns]
GHC is now more diligent about catching illegal uses of kind polymorphism that snuck into recent GHC releases. For instance, this used to be accepted without `PolyKinds`: GHC is now more diligent about catching illegal uses of kind polymorphism that snuck into recent GHC releases. For instance, this used to be accepted without `PolyKinds`:
``` ```hs
class C a where class C a where
c :: Proxy (x :: a) c :: Proxy (x :: a)
``` ```
...@@ -93,7 +103,7 @@ Despite the fact that `a` is used as a kind variable in the type signature for ` ...@@ -93,7 +103,7 @@ Despite the fact that `a` is used as a kind variable in the type signature for `
Moreover, GHC 8.4 would accept the following without the use of `PolyKinds`: Moreover, GHC 8.4 would accept the following without the use of `PolyKinds`:
``` ```hs
f :: forall k (a :: k). Proxy a f :: forall k (a :: k). Proxy a
f = Proxy f = Proxy
``` ```
...@@ -106,14 +116,25 @@ Despite the fact that `k` is used as both a type and kind variable. This is now ...@@ -106,14 +116,25 @@ Despite the fact that `k` is used as both a type and kind variable. This is now
GHC now requires the `UndecidableInstances` extension in order to allow type family applications in instance contexts, as in the following code: GHC now requires the `UndecidableInstances` extension in order to allow type family applications in instance contexts, as in the following code:
``` ```hs
{-# LANGUAGE ConstraintKinds #-}{-# LANGUAGE FlexibleContexts #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE TypeFamilies #-}importData.KindtypefamilyF a ::ConstraintclassC a where{- {-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
import Data.Kind
type family F a :: Constraint
class C a where
{-
Will error without UndecidableInstances: Will error without UndecidableInstances:
• Illegal nested constraint ‘F a’ • Illegal nested constraint ‘F a’
(Use UndecidableInstances to permit this) (Use UndecidableInstances to permit this)
• In the instance declaration for ‘C [[a]]’ • In the instance declaration for ‘C [[a]]’
-}instanceF a =>C[[a]] -}
instance F a => C [[a]]
``` ```
### DPH is gone ### DPH is gone
... ...
......