With respect to Listing 1, how would I go about proving the type level axiom
(t a) = (t (getUI (t a)))
holds?
Listing 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)))
The code is based on a paper where it is stated:
For all implementations of getUI one may require that the axiom (t a) = (t (getUI (t a))) holds. This must be proven to hold for every specific type class instance declaration. For finite types this can be done by a program that enumerates all possibilities. For infinite types this must be done manually via proofs by induction.
My current intuition is that the test
function in some way satisfies the axiom, but I do not think that it amounts to a proof.
This question follows on from a previous question.
答案 0 :(得分:3)
要证明这一点,只需从等式的一侧开始并重写,直到到达另一侧为止。我喜欢从更复杂的方面开始。
when x :: Int,
Continuant (getUI (Continuant x))
-- ^^^^^^^^^^^^^^^^^^^^
-- by definition of getUI in Category Continuant Int
= Continuant x
那很容易!这确实可以作为证明(介意,不是正式验证的证明-Haskell不足以表达术语级的证明。但这太琐碎了,以至于在agda中不值得一试。)
这个公理的措辞让我有些困惑,因为它似乎混淆了很多类型和术语。略读本文,看来这仅适用于简单的单一构造函数newtype
,因此这种混合是合理的(仍然很奇怪)。无论如何,似乎该论文没有在Category
上参数化a
类:即,代替
class Category t a where ...
应该是
class Category t where ...
对我来说更有意义,该类描述了多态包装,而不是关于如何包装每种单独类型的描述(特别是因为看来公理要求实现必须是相同的,而不管{{ 1}}您选择!)。