Skip to content

Commit aaf7fb2

Browse files
author
David Binder
committed
Document GHC-54540
1 parent 1711a4f commit aaf7fb2

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-# LANGUAGE StandaloneDeriving #-}
2+
module ConstructorsNotInScope where
3+
4+
import System.IO( Handle )
5+
6+
-- It is not possible to derive an instance for the typeclass in this module.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-# LANGUAGE StandaloneDeriving #-}
2+
module ConstructorsNotInScope where
3+
4+
import System.IO( Handle )
5+
6+
deriving instance Eq Handle
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Cannot derive an instance for an abstract type
3+
---
4+
5+
The `Handle` type is abstract and does not export its constructors. It is therefore not possible to derive an instance of a typeclass for the `Handle` type in another module. You can only derive an instance of a typeclass in the module where `Handle` is defined.
6+
7+
````
8+
messages/GHC-54540/constructorsNotInScope/before/ConstructorsNotInScope.hs:6:1: error: [GHC-54540]
9+
• Can't make a derived instance of ‘Eq Handle’:
10+
The data constructors of ‘Handle’ are not all in scope
11+
so you cannot derive an instance for it
12+
• In the stand-alone deriving instance for ‘Eq Handle’
13+
|
14+
6 | deriving instance Eq Handle
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Cannot derive instance without constructors in scope
3+
summary: It is not possible to derive a typeclass instance if the constructors of the type are not in scope
4+
severity: error
5+
introduced: 9.6.1
6+
---
7+
8+
Deriving an instance of a typeclass for a type is only possible if the constructors of the type are in scope at the point where you want to derive the instance.

0 commit comments

Comments
 (0)