Skip to content

Commit 01a1047

Browse files
authored
Add example to GHC-88464 (#467)
1 parent 6247f6d commit 01a1047

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module ForgotImport where
2+
3+
import Data.List (sort)
4+
5+
top10 :: [Int] -> [Int]
6+
top10 = take 10 . sort
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ForgotImport where
2+
3+
top10 :: [Int] -> [Int]
4+
top10 = take 10 . sort
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Forgetting an import declaration
3+
---
4+
5+
## Error Message
6+
7+
```
8+
ForgotImport.hs:4:19: error: [GHC-88464]
9+
Variable not in scope: sort :: [Int] -> [Int]
10+
Suggested fix: Perhaps use ‘sqrt’ (imported from Prelude)
11+
|
12+
4 | top10 = take 10 . sort
13+
| ^^^^
14+
```
15+
16+
## Description
17+
In this example, the programmer forgot to import the `sort` function from the `Data.List` module. The updated version adds the appropriate import declaration.

message-index/messages/GHC-88464/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ This error means that a variable name used in a program can't be matched up with
99

1010
In Haskell, every variable comes into existence at a specific location. Examples include function argument names, local definitions with `let`, and module-level definitions. Creating a new name like this is called _binding_ it, and the area of the program that can refer to the new name is called its _scope_. The message means that the provided name is not available for reference right where it is referred to.
1111

12+
A common situation where this error occurs is when the programmer forgets to import some name from a module. In that case, the solution is to add the missing import declaration.
13+
1214
## Example error text
1315

1416
```
1517
error: [GHC-88464] Variable not in scope: x
1618
```
1719

20+
```
21+
error: [GHC-88464] Variable not in scope: sort :: [Int] -> [Int]
22+
```

0 commit comments

Comments
 (0)