Agda: Internal error for local modules with refined parameters

Created on 12 Jan 2018  Â·  4Comments  Â·  Source: agda/agda

module _ where

open import Agda.Builtin.Nat
open import Agda.Builtin.Equality

module M (n : Nat) (m : Nat) where

  foo : n ≡ 0 → Nat
  foo refl = 0
    module M' where
      bar : Nat
      bar = m

  bad : Nat
  bad = M'.bar -- internal error Monad.Signature:882

The local module M' just has the m parameter since n has been refined. This causes problems when we exit the scope of M'.

false modules parameter-refinement bug

Most helpful comment

You can also prove false:

module _ where

open import Agda.Builtin.Nat
open import Agda.Builtin.Equality

data ⊥ : Set where

T : Nat → Set
T zero    = ⊥
T (suc n) = Nat

module M (n : Nat) where

  foo : n ≡ 0 → T n → Nat
  foo refl t = 0
    module M' where
      bar : ⊥
      bar = t

  bad : ⊥
  bad = M'.bar

loop : ⊥
loop = M.bad 0

All 4 comments

You can also prove false:

module _ where

open import Agda.Builtin.Nat
open import Agda.Builtin.Equality

data ⊥ : Set where

T : Nat → Set
T zero    = ⊥
T (suc n) = Nat

module M (n : Nat) where

  foo : n ≡ 0 → T n → Nat
  foo refl t = 0
    module M' where
      bar : ⊥
      bar = t

  bad : ⊥
  bad = M'.bar

loop : ⊥
loop = M.bad 0

There might be a story on inverting the module parameter substitution that makes sense of this example, but I think the best fix for now is to disallow named where modules if the module parameters have been refined.

Are you sure that anonymous where modules are unaffected by this kind of problem?

Reasonably sure. The module parameter substitution is only used to insert the module parameter arguments when the user explicitly references a name. Since you can't reference definitions from anonymous where modules it wouldn't be a problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guillaumebrunerie picture guillaumebrunerie  Â·  3Comments

UlfNorell picture UlfNorell  Â·  3Comments

GoogleCodeExporter picture GoogleCodeExporter  Â·  4Comments

andreasabel picture andreasabel  Â·  3Comments

mdimjasevic picture mdimjasevic  Â·  3Comments