Variable not in scope [GHC-88464]

This error means that a variable name used in a program can’t be matched up with a corresponding binding site.

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.

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.

Example error text

error: [GHC-88464] Variable not in scope: x
error: [GHC-88464] Variable not in scope: sort :: [Int] -> [Int]

Examples

Attempted to refer to another function's argument

Error Message

Main.hs:5:7: error: [GHC-88464]
    Variable not in scope: x
  |
5 | g y = x
  |       ^

Description

In this example, the body of g attempts to refer to x, which is an argument to f and thus not available. The updated version renames g’s argument so that the x in the body can refer to it.

Main.hs
Before
module Main where

f x = 5

g y = x
After
module Main where

f x = 5

g x = x
Forgetting an import declaration

Error Message

ForgotImport.hs:4:19: error: [GHC-88464]
    Variable not in scope: sort :: [Int] -> [Int]
    Suggested fix: Perhaps use ‘sqrt’ (imported from Prelude)
  |
4 | top10 = take 10 . sort
  |                   ^^^^

Description

In this example, the programmer forgot to import the sort function from the Data.List module. The updated version adds the appropriate import declaration.

ForgotImport.hs
Before
module ForgotImport where

top10 :: [Int] -> [Int]
top10 = take 10 . sort
After
module ForgotImport where

import Data.List (sort)

top10 :: [Int] -> [Int]
top10 = take 10 . sort