使依赖参数在 Functor 定义中可用

Make dependent parameter available in Functor definition

我有以下 Vect

的包装器
data Foo : (r : Nat) -> (t: Type) -> Type where
  MkFoo : Vect r t -> Foo r t

我想为 Foo 实现 Functor,并在实现中使用 r 的值,但我无法编译它。

Functor (Foo r) where
  map f (MkFoo v) = MkFoo (ff v) where
    ff : {r' : Nat} -> Vect r' a -> Vect r' b

给予

Error: While processing right hand side of map. r is not accessible in this
context.

Foo.idr:61:28--61:32
    |
 61 |   map f (MkFoo v) = MkFoo (ff v) where
    |                            ^^^^

这在 Idris 1 中有效,但我不知道如何将它移植到 Idris2。我试过 r 不被删除,

Functor ({r : _} -> Foo r) where
  map f (MkFoo v) = MkFoo (ff v) where
    ff : {r' : Nat} -> Vect r' a -> Vect r' b

但我明白了

Error: While processing type
of Functor implementation at Foo.idr:60:1--62:46. When
unifying Type -> Type and Type.
Mismatch between: Type -> Type and Type.

Foo.idr:60:21--60:26
    |
 60 | Functor ({r : _} -> Foo r) where
    |                     ^^^^^

尝试:

{r : _} -> Functor (Foo r) where
  map f (MkFoo v) = MkFoo (ff v) where
    ff : {r' : Nat} -> Vect r' a -> Vect r' b