scope - 存在于 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
鉴于文档中的内容,我不明白这一点
在外部范围内可见的任何名称在 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'
解决方案
你似乎在寻找let
不where
。外部范围意味着foo
.
推荐阅读
- java - Drools:为多个请求重用相同的 Kiesession
- r - 如何消除另一个数据框中基于列名的数据框中的行
- c - 线的最大长度
- prolog - 如何在 Prolog 代码本身中编写“findall”?
- javascript - 根据子对象数组的字段对对象数组进行排序
- python - 为什么在这个对 iter 的调用中哨兵是强制性的?
- reactjs - Props 对象从 React 官方文档中传子给组件是什么意思
- reactjs - 我不能用钩子。我不能用对象设置用户。我应该怎么办?
- java - 带有内部枚举类的 Eclipse AST 的奇怪结果
- java - 如果绑定到 Container-Height,ScrollPane 不会立即调整 ViewPort-Height 的大小