Stream Idris中流函数性质的证明

Stream Idris中流函数性质的证明,stream,idris,dependent-type,frp,Stream,Idris,Dependent Type,Frp,我试图证明流函数和一元流函数的性质[1](最终是FRP程序) Idris对我对流函数的形式化表示满意: module SF import Data.Vect import Syntax.PreorderReasoning %default total data SF : Type -> Type -> Type where SFG : (a -> (b, Inf (SF a b))) -> SF a b steps : {n : Nat} -> SF a

我试图证明流函数和一元流函数的性质[1](最终是FRP程序)

Idris对我对流函数的形式化表示满意:

module SF

import Data.Vect
import Syntax.PreorderReasoning

%default total

data SF : Type -> Type -> Type where
  SFG : (a -> (b, Inf (SF a b))) -> SF a b

steps : {n : Nat} -> SF a b -> Vect n a -> Vect n b
steps {n = Z}   (SFG s) []        = []
steps {n = S m} (SFG s) (a :: as) =
    let (b, s') = s a
        bs = steps s' as
    in (b::bs)
liftM : (a -> b) -> SF a b
liftM f = SFG $ \a => (f a, liftM f)
我可以简单地定义提升/逐点应用程序函数:

module SF

import Data.Vect
import Syntax.PreorderReasoning

%default total

data SF : Type -> Type -> Type where
  SFG : (a -> (b, Inf (SF a b))) -> SF a b

steps : {n : Nat} -> SF a b -> Vect n a -> Vect n b
steps {n = Z}   (SFG s) []        = []
steps {n = S m} (SFG s) (a :: as) =
    let (b, s') = s a
        bs = steps s' as
    in (b::bs)
liftM : (a -> b) -> SF a b
liftM f = SFG $ \a => (f a, liftM f)
以及SFs标识的两种变体:

identityM : SF a a
identityM = SFG $ \a => (a, identityM)

identity2 : SF a a
identity2 = liftM id
这将通过Idris的总体检查。然而,如果我现在试图证明
identityM
identity2
是相等的,我就会遇到问题。我可以将财产陈述如下:

proof1 :  (Eq b)
       => (n : Nat)
       -> (v : Vect n a)
       -> (steps identityM v) = (steps identity2 v)
proof1 Z [] = ?proof1_rhs_1
proof1 (S k) v = ?proof1_rhs_2
如果我询问
?proof1_rhs_1
的类型,idris正确地说
步骤标识YM[]=步骤标识2[]
。然而,如果我试图用等式推理来表达:

proof1 Z [] = (steps {n=Z} identityM []) ={ ?someR }=
              (steps {n=Z} identity2 []) QED
伊德里斯很不高兴:

When checking argument x to function Syntax.PreorderReasoning.Equal.qed:
        Type mismatch between
                steps identity2 [] (Inferred value)
        and
                steps identity2 [] (Given value)

        Specifically:
                Type mismatch between
                        steps identity2
                and
                        []Unification failure
有什么办法可以让这一切顺利进行吗

[1]

通常的“Idris”隐式泛化会导致范围规则混乱:

意味着


要参考前面的定义,您需要使用限定名称
SF.identityM
SF.identity2
。您可能还有其他问题(
Eq b
b
在类型的其余部分中没有提及,这似乎是可疑的)。

您是对的。但是,当我这样做时,如果我在
v
的构造函数上展开/pattern match,我会得到错误:
x::steps(SFG(\a=>(a,Delay identityM)))xs=x::steps(SFG(\a=>(a,Delay(liftM id)))xs和x::steps identityM xs=x::steps(liftM id)xs