Agda: Agda cannot infer instance arguments between modules under certain circumstances

Created on 3 Dec 2016  ยท  4Comments  ยท  Source: agda/agda

postulate
  X A : Set

module Foo {{x : X}} where

  postulate
    B C : Set
    foo : A โ†’ B โ†’ C โ†’ Set

module Bar {{x : X}} where
  open Foo

  postulate
    -- The following fails to infer the instance argument if we do not either:
    --   * apply {{x}} explicitly to foo
    --   * apply {{x}} explicitly when opening module Foo
    --   * define fail1 in module Foo
    fail1 : โˆ€ {a b b' c c'} โ†’ foo a b c โ†’ foo a b' c'

    -- However, the following works
    work1 : โˆ€ {a b c} โ†’ foo a b c โ†’ foo a b c
    work2 : โˆ€ {a a' b c} โ†’ foo a b c โ†’ foo a' b c
    work3 : โˆ€ {a b b' c} โ†’ foo a b c โ†’ foo a b' c
    work4 : โˆ€ {a a' b b' c} โ†’ foo a b c โ†’ foo a' b' c
    work5 : โˆ€ {a b c c'} โ†’ foo a b c โ†’ foo a b c'
    work6 : โˆ€ {a a' b c c'} โ†’ foo a b c โ†’ foo a' b c'
    work7 : โˆ€ {a a' b b' c c'} โ†’ foo a b c โ†’ foo a' b' c'

Tested in Agda version 2.5.1.1 and 2.6.0-989c97c

highlighting instance meta bug

All 4 comments

It looks like the problem is that we lose the instance constraint when the original meta variable is pruned.

What about this one?

data Nat : Set where
  suc : Nat โ†’ Nat
  instance
    zero : Nat

instance
  one = suc zero

data IsSuc : Nat โ†’ Set where
  isSuc : โˆ€{n} โ†’ IsSuc (suc n)

postulate
  F : {{x : Nat}} (p : IsSuc x) โ†’ Set

test = F isSuc  -- yellow, but should not be

The instance meta is partially solved by suc _ and the instance constraint is discarded, even though only one instance applies now (one).

For reference, the check for solved metas was introduced in the fix of #1003.

Ah, no one was watching my fingers then... ;-)
Thanks for fixing.

Was this page helpful?
0 / 5 - 0 ratings