Skip to content

GHC should suggest enabling -XScopedTypeVariables

{-# language AllowAmbiguousTypes, TypeApplications #-}
module Scoped where

import Numeric.Natural

class ReifyNat a where
  reifyNat :: Natural

data Z
data S a

instance ReifyNat Z where
  reifyNat = 0
instance ReifyNat a => ReifyNat (S a) where
  reifyNat = 1 + reifyNat @a
$ ghc-9.0.1 Scoped.hs 
[1 of 1] Compiling Scoped           ( Scoped.hs, Scoped.o )

Scoped.hs:15:28: error: Not in scope: type variable ‘a’
   |
15 |   reifyNat = 1 + reifyNat @a
   |                            ^

It would be nice if GHC could suggest enabling -XScopedTypeVariables here.

(The example is from https://lexi-lambda.github.io/blog/2021/03/25/an-introduction-to-typeclass-metaprogramming/.)

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information