匹配存在性隐藏类型索引

时间:2017-08-11 12:38:45

标签: idris existential-type

我想匹配'存在隐藏'类型索引,以便编写Eq实例:

module Test

import Data.Vect

data Meep : Type where
  Moop : {n:Nat} -> Vect n Int -> Meep

Eq Meep where
  (Moop {n1} v1) == (Moop {n2} v2) = False

随后,我希望了解decEq n1 n2以委托给Eq (Vect n Int)或返回False

但上述似乎不起作用:

Type checking .\.\Test.idr
.\.\Test.idr:9:9:
When checking left hand side of Prelude.Interfaces.Test.Meep implementation of Prelude.Interfaces.Eq, method ==:
n1 is not an implicit argument of Test.Moop

Idris的实际做法是什么?

1 个答案:

答案 0 :(得分:3)

你可以这样做:

Eq Meep where
  (Moop {n = n1} v1) == (Moop {n = n2} v2) with (decEq n1 n2)
    (Moop {n = n2} v1) == (Moop {n = n2} v2) | (Yes Refl) = v1 == v2
    (Moop {n = n1} v1) == (Moop {n = n2} v2) | (No contra) = False