"Undefined name" 对于存在于 where 外部范围内的值
"Undefined name" for value present in outer scope of where
我想使用在 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
中的内容,我不明白
Any names which are visible in the outer scope are also visible in the where clause (unless they have been redefined, such as xs here). A name which appears in the type will be in scope in the where clause.
将 x 绑定到 RHS 上的新名称
foo : Nat
foo = case Just 1 of
Nothing => 0
Just x => let x' = x in bar where
bar : Nat
bar = x'
对于 bar = x'
产生类似的错误 Undefined name x'
您似乎在寻找 let
而不是 where
。外部范围意味着 foo
.
的参数
我想使用在 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
中的内容,我不明白Any names which are visible in the outer scope are also visible in the where clause (unless they have been redefined, such as xs here). A name which appears in the type will be in scope in the where clause.
将 x 绑定到 RHS 上的新名称
foo : Nat
foo = case Just 1 of
Nothing => 0
Just x => let x' = x in bar where
bar : Nat
bar = x'
对于 bar = x'
Undefined name x'
您似乎在寻找 let
而不是 where
。外部范围意味着 foo
.