- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对向量谓词有以下定义,用于标识一个集合是否为集合(没有重复元素)。我使用类型级 bool 值定义成员资格:
import Data.Vect
%default total
data ElemBool : Eq t => t -> Vect n t -> Bool -> Type where
ElemBoolNil : Eq t => ElemBool {t=t} a [] False
ElemBoolCons : Eq t => ElemBool {t=t} x1 xs b -> ElemBool x1 (x2 :: xs) ((x1 == x2) || b)
data IsSet : Eq t => Vect n t -> Type where
IsSetNil : Eq t => IsSet {t=t} []
IsSetCons : Eq t => ElemBool {t=t} x xs False -> IsSet xs -> IsSet (x :: xs)
现在我定义了一些允许我创建这个谓词的函数:
fun_1 : Eq t => (x : t) -> (xs : Vect n t) -> (b : Bool ** ElemBool x xs b)
fun_1 x [] = (False ** ElemBoolNil)
fun_1 x1 (x2 :: xs) =
let (b ** prfRec) = fun_1 x1 xs
in (((x1 == x2) || b) ** (ElemBoolCons prfRec))
fun_2 : Eq t => (xs : Vect n t) -> IsSet xs
fun_2 [] = IsSetNil
fun_2 (x :: xs) =
let prfRec = fun_2 xs
(False ** isNotMember) = fun_1 x xs
in IsSetCons isNotMember prfRec
fun_1
的工作方式类似于 ElemBool 上的决策过程。
我的问题是 fun_2
。为什么 (False ** isNotMember) = fun_1 x xs
上的模式匹配会进行类型检查?
更令人困惑的是,还有类似以下类型检查的内容:
example : IsSet [1,1]
example = fun_2 [1,1]
根据上面 IsSet 和 ElemBool 的定义,这似乎是矛盾的。ví dụ
idris 计算的值如下:
case block in fun_2 Integer
1
1
[1]
(constructor of Prelude.Classes.Eq (\meth =>
\meth =>
intToBool (prim__eqBigInt meth
meth))
(\meth =>
\meth =>
not (intToBool (prim__eqBigInt meth
meth))))
(IsSetCons ElemBoolNil IsSetNil)
(True ** ElemBoolCons ElemBoolNil) : IsSet [1, 1]
这是有意为之的行为吗?还是自相矛盾?为什么 IsSet [1,1]
类型的值是 case block ?我在文件顶部有 %default total
注释,所以我认为它与偏袒没有任何关系,对吧?
Để ý:我使用的是 Idris 0.9.18
1 Câu trả lời
覆盖率检查器中存在一个错误,这就是此类型检查的原因。它将在 0.9.19 中修复(这是一个微不足道的问题,由内部依赖对构造函数的名称更改引起,由于某种原因,直到现在才被忽视,所以感谢你提醒我!)
无论如何,我按如下方式实现了fun_2
:
fun_2 : Eq t => (xs : Vect n t) -> Maybe (IsSet xs)
fun_2 [] = Just IsSetNil
fun_2 (x :: xs) with (fun_1 x xs)
fun_2 (x :: xs) | (True ** pf) = Nothing
fun_2 (x :: xs) | (False ** pf) with (fun_2 xs)
fun_2 (x :: xs) | (False ** pf) | Nothing = Nothing
fun_2 (x :: xs) | (False ** pf) | (Just prfRec)
= Just (IsSetCons pf prfRec)
因为不是所有的Vect
都可以被设置,这需要返回一个Maybe
。可悲的是,它不能返回更精确的东西,比如 Dec (IsSet xs)
因为你使用的是通过 Eq
的 bool 相等性,而不是通过 DecEq 的可判定相等性
但也许这就是您想要的集合版本。
关于proof - Idris 中看似矛盾的类型检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32110475/
在 Coq 中,我有两个假设 H 和 H0 ,它们相互矛盾。问题是,它们只是在某些特化方面相互矛盾,而在证明的这一刻,上下文并不是那么特化。 此时我的证明上下文如下所示: color : Vertex
根据 RubyMonk section 8.1模块只保存行为而不保存状态,类可以保存行为和状态。 然而,模块是 Ruby 中类的父类(super class)。怎么会这样? 最佳答案 哦兄弟,如果你忘
来自此处的文档:http://facebook.github.io/react/docs/pure-render-mixin.html 脚注说如果复杂数据(深层数据结构)的结构发生变化,你应该使用fo
我有一个简单的类(class) function TrueNinja() { this.vanish = function() { return this; }; } 由此创建一个新对象 var
这个问题在这里已经有了答案: How do Python's any and all functions work? (10 个答案) 关闭 4 年前。 无意中发现了Numpy中的一些东西,实在看不
这个问题在这里已经有了答案: C++ doesn't tell you the size of a dynamic array. But why? (7 个回答) 关闭3年前。 我到处都读到,在 C+
编辑以提供完整的代码示例和特定问题 我正在编写一个函数来生成股票价格的时间序列图。但是,出现以下错误 eval(expr,envir,enclos)中的错误:找不到对象'df1234' 这是该函数的示
Đã đóng. Sự cố này cần có thông tin chi tiết để gỡ lỗi. Hiện tại không chấp nhận câu trả lời. Chỉnh sửa câu hỏi để bao gồm hành vi mong muốn, một vấn đề hoặc lỗi cụ thể và
我正在阅读 Stroustrup 的 C++(1997 年第 3 版)以了解他是如何实现 RAII 的,在第 365 页上我发现了这一点: class File_ptr{ FILE* p; p
A class S is a standard-layout class if it: [class.prop]/(3.7) : has no element of the set M(S) of t
Tôi là một lập trình viên xuất sắc, rất giỏi!