【发布时间】:2019-09-05 10:53:13
【问题描述】:
总的来说,我是 Idris 和 Proofs 的新手,但我正在通过移植到 Idris 的软件基础取得进展。我正在做一个练习
namespace Booleans
data Bool = True | False
andb : Booleans.Bool -> Booleans.Bool -> Booleans.Bool
andb True b = b
andb False _ = False
orb : Booleans.Bool -> Booleans.Bool -> Booleans.Bool
orb True _ = True
orb False b = b
(&&) : Booleans.Bool -> Booleans.Bool -> Booleans.Bool
(&&) = andb
(||) : Booleans.Bool -> Booleans.Bool -> Booleans.Bool
(||) = orb
andb_eq_orb : (b, c : Booleans.Bool) -> (b && c = b || c) -> b = c
显然有四种情况,两种情况适用于自反性。
andb_eq_orb True True _ = Refl
andb_eq_orb True False prf = ?rhs1
andb_eq_orb False True prf = ?rhs2
andb_eq_orb False False _ = Refl
检查漏洞
Main.Booleans.rhs1
prf : True && False = True || False
---------------------------------
Main.Booleans.rhs1 : True = False
Main.Booleans.rhs2
prf : False && True = False || True
---------------------------------
Main.Booleans.rhs2 : False = True
我不明白,虽然这些断言显然不合逻辑,但我需要为这两个步骤证明这一点。我没有看到我可以做的任何重写步骤。更多但抽象地,我不理解在语言中逻辑或明确地解决这个问题的方法或模式(伊德里斯)。
我可以通过为类型签名实现 Uninhabbited 接口来使这两种方法都起作用:
Uninhabited (Booleans.True && Booleans.False = Booleans.True || Booleans.False) where
uninhabited Refl impossible
【问题讨论】: