Interface 与Idris中所需证明的接口

Interface 与Idris中所需证明的接口,interface,proof,idris,Interface,Proof,Idris,在过去的几天里,我一直在努力学习伊德里斯的书。在阅读了关于等式证明的部分之后,我开始考虑拥有一个需要一些等式证明的接口。让我们举几个例子: interface ProperFunctor (f : Type -> Type) where fmap : (a -> b) -> f a -> f b functorial : {phi : b -> c} -> {psi : a -> b} -> {fx : f a} ->

在过去的几天里,我一直在努力学习伊德里斯的书。在阅读了关于等式证明的部分之后,我开始考虑拥有一个需要一些等式证明的接口。让我们举几个例子:

interface ProperFunctor (f : Type -> Type) where
  fmap : (a -> b) -> f a -> f b
  functorial : {phi : b -> c} -> {psi : a -> b} -> {fx : f a} ->
               fmap (phi . psi) fx = (fmap phi . fmap psi) fx
此接口的一个可能实例是任何实际上是一个函子的函子(即满足函子性的函子,除了类型正确的
fmap
)。同样,一个例子胜过一百万字:

ProperFunctor List where
  fmap f [] = []
  fmap f (x :: xs) = f x :: fmap f xs

  functorial = ?functorial_rhs
如何填补这个漏洞

当然,为隐式参数提供显式值确实有帮助,类型检查也是如此

ProperFunctor List where
  fmap f [] = []
  fmap f (x :: xs) = f x :: fmap f xs

  functorial {phi} {psi} {fx = []) = Refl
  functorial {phi} {psi} {fx = (x :: xs)} = ?functorial_rhs_2
在这一点上,完成证明的最自然的方式(至少对我来说)似乎是在
fx
上归纳:

ProperFunctor List where
  fmap f [] = []
  fmap f (x :: xs) = f x :: fmap f xs

  functorial {phi} {psi} {fx = []) = Refl
  functorial {phi} {psi} {fx = (x :: xs)} =
    let indHyp = functorial {phi} {psi} {fx = xs}
    in rewrite indHyp in Refl
所有这些实际上都正确地进行了类型检查,但当我试图删除
let
子句时,发生了一件奇怪的事情:

ProperFunctor List where
  fmap f [] = []
  fmap f (x :: xs) = f x :: fmap f xs

  functorial {phi} {psi} {fx = []) = Refl
  functorial {phi} {psi} {fx = (x :: xs)} =
    rewrite (functorial {phi} {psi} {fx = xs}) in Refl
不再进行类型检查:我收到一条“找不到PropertFunctor f的实现”,然后是一条关于类型不匹配的错误消息(我似乎无法理解):

类型检查。/.idr
.idr:17:5-54:
|
17 |在Refl中重写(函数{phi}{psi}{fx=xs})
|     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
检查Main.ProperFunctor的Main.Main.List实现的右侧时,方法functional应为预期类型
Main.List Main.ProperFunctor方法fmap c a(phi.psi)(x::xs)的实现=
(Main.ProperFunctor的Main.List实现,方法fmap c b phi.Main.List Main.ProperFunctor的实现,方法fmap b a psi)(x::xs)
找不到PropertFunctor f的实现
可能原因:
.idr:17:13-46:检查函数重写的应用程序时:
之间的类型不匹配
phi2(psi3 x):Main.ProperFunctor的Main.List实现,方法fmap c1 b4 phi2(Main.ProperFunctor的Main.List实现,方法fmap b4 a5 psi3 xs)=
phi2(psi3 x)::
Main.List实现Main.ProperFunctor,方法fmap c1 b4 phi2(Main.List实现Main.ProperFunctor,方法fmap b4 a5 psi3 xs)(反射类型)
和
(\r=>
phi2(psi3 x):已更换=
phi2(psi3 x)::
Main.ProperFunctor的Main.List实现,方法fmap c1 b4 phi2(Main.ProperFunctor的Main.List实现,方法fmap b4 a5 psi3 xs))(fmap phi
(fmap psi)
(预期类型)
明确地:
之间的类型不匹配
Main.List实现Main.ProperFunctor,方法fmap c1 b2 phi3(Main.List实现Main.ProperFunctor,方法fmap b2 a4 psi5 xs)
和
fmap phi(fmap psi外汇)
这是怎么回事?我是否使用了错误的
let
,这是因为
rewrite
的工作原理造成的,还是我完全误解了如何使用这些功能?任何提示都将不胜感激,提前感谢

PS:我在ArchLinux上使用IDRIS1.3.2;我不认为这与我的问题有任何关系,但如果这是一个bug,它可能会发生

Type checking ./<file>.idr
<file>.idr:17:5-54:
   |
17 |     rewrite (functorial {phi} {psi} {fx = xs}) in Refl
   |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When checking right hand side of Main.Main.List implementation of Main.ProperFunctor, method functorial with expected type
        Main.List implementation of Main.ProperFunctor, method fmap c a (phi . psi) (x :: xs) =
        (Main.List implementation of Main.ProperFunctor, method fmap c b phi . Main.List implementation of Main.ProperFunctor, method fmap b a psi) (x :: xs)

Can't find implementation for ProperFunctor f

Possible cause:
        <file>.idr:17:13-46:When checking an application of function rewrite__impl:
                Type mismatch between
                        phi2 (psi3 x) :: Main.List implementation of Main.ProperFunctor, method fmap c1 b4 phi2 (Main.List implementation of Main.ProperFunctor, method fmap b4 a5 psi3 xs) =
                        phi2 (psi3 x) ::
                        Main.List implementation of Main.ProperFunctor, method fmap c1 b4 phi2 (Main.List implementation of Main.ProperFunctor, method fmap b4 a5 psi3 xs) (Type of Refl)
                and
                        (\replaced =>
                           phi2 (psi3 x) :: replaced =
                           phi2 (psi3 x) ::
                           Main.List implementation of Main.ProperFunctor, method fmap c1 b4 phi2 (Main.List implementation of Main.ProperFunctor, method fmap b4 a5 psi3 xs)) (fmap phi
                                                                                                                                                                                     (fmap psi
                                                                                                                                                                                           fx)) (Expected type)

                Specifically:
                        Type mismatch between
                                Main.List implementation of Main.ProperFunctor, method fmap c1 b2 phi3 (Main.List implementation of Main.ProperFunctor, method fmap b2 a4 psi5 xs)
                        and
                                fmap phi (fmap psi fx)