-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document GHC 91999 and GHC 86639 #507
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{-# LANGUAGE DeriveFunctor #-} | ||
module AddAFunctor where | ||
|
||
data MyFunctor a = MyFunctor a a | ||
deriving Functor |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module AddAFunctor where | ||
|
||
data MyFunctor a = MyFunctor a a | ||
deriving Functor |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||
--- | ||||||
title: Require the DerivingFunctor language extension for Functor instances | ||||||
--- | ||||||
|
||||||
When deriving a `Functor` instance for a datatype in Haskell2010, the | ||||||
`DerivingFunctor` language extension must be turned on. This can be done with a | ||||||
pragma at the top of the file, or in build settings. | ||||||
|
||||||
The `DerivingFunctor` extension is turned on automatically from Haskell2021 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
onwards. |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,20 @@ | ||||||||
--- | ||||||||
title: Cannot derive an instance without a corresponding language extension | ||||||||
summary: A language extension must be turned on for a typeclass to be derived. | ||||||||
severity: error | ||||||||
introduced: 9.6.1 | ||||||||
--- | ||||||||
|
||||||||
Some typeclasses can be derived automatically in the `deriving` declaration, but | ||||||||
require a certain language extension to be turned on. | ||||||||
|
||||||||
For example, to derive `Functor` on a datatype, the `DeriveFunctor` language | ||||||||
extension must be turned on. | ||||||||
|
||||||||
There are many available language extensions for deriving instances, the | ||||||||
appropriate extension depends on the typeclass -- for example, deriving `Functor` | ||||||||
requires the `DeriveFunctor` language extension, deriving `Generic` requires | ||||||||
`DeriveGeneric`, and deriving `Lift` requires `DeriveLift`, among others. | ||||||||
|
||||||||
There is more info on deriving instances for extra typeclasses in the [GHC user | ||||||||
manual](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/deriving_extra.html). | ||||||||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GitLab links can change, better to link documentation of a stable GHC release:
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module BootModuleDataTypeNotInOrdinaryModule where | ||
|
||
data BootModuleOnlyDataType = BootModuleOnlyDataType String |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module BootModuleDataTypeNotInOrdinaryModule where | ||
|
||
data BootModuleOnlyDataType = BootModuleOnlyDataType String |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module ImportBootModule where | ||
|
||
import {-# SOURCE #-} BootModuleDataTypeNotInOrdinaryModule |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module BootModuleDataTypeNotInOrdinaryModule where | ||
|
||
-- Defined only in the .hs-boot version of this module | ||
-- data BootModuleOnlyDataType = BootModuleOnlyDataType String |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module BootModuleDataTypeNotInOrdinaryModule where | ||
|
||
data BootModuleOnlyDataType = BootModuleOnlyDataType String |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module ImportBootModule where | ||
|
||
import {-# SOURCE #-} BootModuleDataTypeNotInOrdinaryModule |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: Boot module has a datatype which isn't in its corresponding ordinary module | ||
--- | ||
|
||
In this example, we define a datatype `BootModuleOnlyDataType` in | ||
`BootModuleDataTypeNotInOrdinaryModule.hs-boot`. | ||
|
||
Compile the example files like so: | ||
|
||
```sh | ||
ghc -c BootModuleDataTypeNotInOrdinaryModule.hs-boot | ||
ghc -c ImportBootModule.hs | ||
ghc -c BootModuleDataTypeNotInOrdinaryModule.hs | ||
``` | ||
|
||
In the before case, where we defined the datatype `BootModuleOnlyDataType` only | ||
in `BootModuleDataTypeNotInOrdinaryModule.hs-boot`, we compile the modules like | ||
so and receive the following error: | ||
|
||
``` | ||
<no location info>: error: | ||
‘BootModuleDataTypeNotInOrdinaryModule.BootModuleOnlyDataType’ is exported by the hs-boot file, but not exported by the module | ||
``` | ||
|
||
In the after case, we add the datatype to | ||
`BootModuleDataTypeNotInOrdinaryModule.hs`, and the error disappears. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,11 @@ | ||||||
--- | ||||||
title: Missing Boot Export | ||||||
summary: An hs-boot file exports a datatype that isn't found in its corresponding .hs file | ||||||
severity: error | ||||||
introduced: 9.8.1 | ||||||
--- | ||||||
|
||||||
Any datatype that is exported from an .hs-boot file must be exported from the | ||||||
corresponding .hs file. | ||||||
|
||||||
More information on .hs-boot modules is available in [the GHC user manual](https://downloads.haskell.org/ghc/latest/docs/users_guide/separate_compilation.html#how-to-compile-mutually-recursive-modules). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The anchor is gone, I guess it's now
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth mentioning that
DeriveTraversable
impliesDeriveFunctor
and also fixes the error.