簡體   English   中英

VerifiedFunctor - 證明映射(map g) x = x

[英]VerifiedFunctor - prove map (map g) x = x

我試圖證明關於VerifiedFunctor接口的聲明( map方法尊重身份和組合的Functor ):

interface Functor f => VerifiedFunctor (f : Type -> Type) where
    functorIdentity : {a : Type} -> (g : a -> a) -> ((v : a) -> g v = v) ->
                      (x : f a) -> map g x = x

這是聲明(從邏輯上講,兩個給定函子的map . map也尊重身份):

functorIdentityCompose : (VerifiedFunctor f1, VerifiedFunctor f2) =>
                         (g : a -> a) -> ((v : a) -> g v = v) ->
                         (x : f2 (f1 a)) -> map (map g) x = x
functorIdentityCompose fnId prId = functorIdentity (map fnId) (functorIdentity fnId prId)

但是,我收到以下錯誤:

Type mismatch between
        (x : f1 a) -> map fnId x = x (Type of functorIdentity fnId prId)
and
        (v : f a) -> map fnId v = v (Expected type)

Specifically:
        Type mismatch between
                f1 a
        and
                f a

我試圖指定所有隱式參數:

functorIdentityCompose : (VerifiedFunctor f1, VerifiedFunctor f2) =>
                         {a : Type} -> {f1 : Type -> Type} -> {f2 : Type -> Type} ->
                         (g : a -> a) -> ((v : a) -> g v = v) -> (x : f2 (f1 a)) ->
                         map {f=f2} {a=f1 a} {b=f1 a} (map {f=f1} {a=a} {b=a} g) x = x

...但又出現了一個錯誤:

When checking argument func to function Prelude.Functor.map:
        Can't find implementation for Functor f15

那么任何想法這里有什么問題以及如何證明這個陳述?

這是一個啟發式:當“明顯”的事情不起作用時...... eta-expand! 所以這有效:

functorIdentityCompose : (VerifiedFunctor f1, VerifiedFunctor f2) =>
  (g : a -> a) -> ((v : a) -> g v = v) ->
  (x : f2 (f1 a)) -> map (map g) x = x
functorIdentityCompose fnId prId x =
  functorIdentity (map fnId) (\y => functorIdentity fnId prId y) x

看起來完整的應用程序會觸發實例搜索。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM