【发布时间】:2019-01-18 19:10:08
【问题描述】:
关于 清单 1,我将如何证明类型级公理
(t a) = (t (getUI (t a)))
持有?
清单 1
data Continuant a = Continuant a deriving (Show,Eq)
class UI a where -- ...
instance UI Int where -- ...
class Category t where
getUI :: (UI a) => (t a) -> a
instance Category Continuant where
getUI (Continuant a) = a
-- Does axiom (t a) = (t (getUI(t a))) holds for given types?
test :: Int -> Bool
test x = (Continuant x) == (Continuant (getUI (Continuant x)))
代码基于paper 声明:
对于 getUI 的所有实现,可能需要公理 (t a) = (t (getUI (t a))) 成立。这必须被证明适用于每个特定类型类实例声明。对于有限类型,这可以是 由枚举所有可能性的程序完成。对于无限 类型这必须通过归纳证明手动完成。
我目前的直觉是 test 函数在某种程度上满足公理,但我认为它不等于证明。
这个问题来自previous question。
【问题讨论】:
-
UI类有什么用?它没有方法,没有约束,也没有功能依赖。这似乎使它变得毫无用处。 -
@dfeuer。 UI 是唯一标识符的类。代码已被简化以专注于证明。所以,在代码的上下文中,类只是作为对类型变量的约束。
-
啊...当我写这样的例子时,我通常会使用省略号来表示体内有东西。
class UI a where ...,instance UI Int where ....