【发布时间】:2021-03-14 15:11:06
【问题描述】:
我想使用在 where 子句的外部范围中定义的值,就像这样
foo : Nat
foo = case Just 1 of
Nothing => 0
Just x => bar where
bar : Nat
bar = x
但我得到了
Error: While processing right hand side of foo. While processing right hand side of foo,bar. Undefined name x.
Foo.idr:30:11--30:12
|
30 | bar = x
鉴于the docs 中所说的内容,我不明白这一点
在外部范围内可见的任何名称在 where 子句中也可见(除非它们已被重新定义,例如此处的 xs)。出现在类型中的名称将在 where 子句的范围内。
将 x 绑定到 RHS 上的新名称
foo : Nat
foo = case Just 1 of
Nothing => 0
Just x => let x' = x in bar where
bar : Nat
bar = x'
导致Undefined name x' 出现类似的错误bar = x'
【问题讨论】: