我建立了一个小TotalTotal类,它具有比常规Ord类更强的证明属性。问题在于,这些属性需要在语法上我不确定该如何相互引用。
我需要在接口的其他方法中引用我的lessThan
类型,但似乎已将其视为常规变量(隐式地称为all)。
module Order
%default total
public export
data Ordering : (t -> t -> Type) -> t -> t -> Type where
LessThan : f x y -> Ordering f x y
Equal : x = y -> Ordering f x y
GreaterThan : f y x -> Ordering f x y
public export
interface TotalOrder a where
lessThan : a -> a -> Type
compare : (x, y : a) -> Ordering lessThan x y
ltNeq : lessThan x y -> x = y -> Void
ltNgt : lessThan x y -> lessThan y x -> Void
-- Implementation for Nats
compareNat : (x, y : Nat) -> Ordering LT x y
compareNat x y = ...
ltNeqNat : LT x y -> x = y -> Void
ltNeqNat lt eq = ...
ltNgtNat : LT x y -> LT y x -> Void
ltNgtNat lt gt = ...
implementation TotalOrder Nat where
lessThan = LT
compare = compareNat -- THIS LINE REFUSES TO COMPILE
ltNeq = ltNeqNat
ltNgt = ltNgtNat
尽我所能确定,类型检查器会自动假定lessThan
和ltNeq
中位于函数位置的ltNgt
与接口中声明的lessThan
相同,但lessThan
中compare
参数位置的位置被视为compare
的常规参数,这意味着Nat实现的类型为
compare : {lessThan : Nat -> Nat -> Type} -> (x, y : Nat) -> Ordering lessThan x y
而不是
compare : (x, y : Nat) -> Ordering LT x y
和compare = compareNat
不再进行类型检查。当我在顶级函数中遇到此问题时,对名称进行完全限定是可行的,但是我不确定此处的完全限定名称是什么,以及显而易见的想法(Order.lessThan
,{{1} },TotalOrder.lessThan
)都得到“没有这样的变量”。