找出所有函数参数模式匹配
Figuring out all functions parameter pattern matches
拥有:
data Bin : Set where
nil : Bin
x0_ : Bin → Bin
x1_ : Bin → Bin
data One : Bin → Set where
one : One (x1 nil)
y0_ : ∀ {bin : Bin} → One bin → One (x0 bin)
y1_ : ∀ {bin : Bin} → One bin → One (x1 bin)
one-ident : ∀ {x : Bin} → One x → to (from x) ≡ x
生成所有函数参数模式匹配的逻辑是什么?
one-ident one = {! !}
one-ident {x0 x} (y0 o) = {! !}
one-ident {x1 x} (y1 o) = {! !}
例如,知道第一个参数是 {x0 x}
为什么第二个参数必须是 (y0 o)
?为什么第二个参数不能是 (y1 o)
?
代码示例取自 here。
one-ident : ∀ {x : Bin} → One x → to (from x) ≡ x
one-ident one = {! !}
one-ident {x0 xx} (y0 o) = {! !}
one-ident {x1 xx} (y1 o) = {! !}
当您知道 x
在 one-ident 中是 x0 xx
时,您就知道第二个参数的类型是 One (x0 xx)
。 One
中只有 1 个构造函数可以具有该类型,即 y0_
.
拥有:
data Bin : Set where
nil : Bin
x0_ : Bin → Bin
x1_ : Bin → Bin
data One : Bin → Set where
one : One (x1 nil)
y0_ : ∀ {bin : Bin} → One bin → One (x0 bin)
y1_ : ∀ {bin : Bin} → One bin → One (x1 bin)
one-ident : ∀ {x : Bin} → One x → to (from x) ≡ x
生成所有函数参数模式匹配的逻辑是什么?
one-ident one = {! !}
one-ident {x0 x} (y0 o) = {! !}
one-ident {x1 x} (y1 o) = {! !}
例如,知道第一个参数是 {x0 x}
为什么第二个参数必须是 (y0 o)
?为什么第二个参数不能是 (y1 o)
?
代码示例取自 here。
one-ident : ∀ {x : Bin} → One x → to (from x) ≡ x
one-ident one = {! !}
one-ident {x0 xx} (y0 o) = {! !}
one-ident {x1 xx} (y1 o) = {! !}
当您知道 x
在 one-ident 中是 x0 xx
时,您就知道第二个参数的类型是 One (x0 xx)
。 One
中只有 1 个构造函数可以具有该类型,即 y0_
.