受歧视的工会可以相互提及吗?
我正在使用可区分联合构建表达式树。以下代码:
type IntExpression =
| TrueIsOne of BoolExpression
type BoolExpression =
| LessThan of IntExpression * IntExpression
| And of BoolExpression * BoolExpression
| Or of BoolExpression * BoolExpression
| Bool of bool
抛出错误,因为未定义 BoolExpression。交换定义只会导致相反的结果(未定义 IntExpression),正如您所期望的那样。
有办法解决这个问题吗?
I'm building an expression tree using discriminated unions. The below code:
type IntExpression =
| TrueIsOne of BoolExpression
type BoolExpression =
| LessThan of IntExpression * IntExpression
| And of BoolExpression * BoolExpression
| Or of BoolExpression * BoolExpression
| Bool of bool
throws an error because BoolExpression is not defined. Swapping the definitions just results in the reverse (IntExpression is not defined) as you would expect.
Is there a way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许这会起作用:(
信息取自MSDN 上的此页面。 )
Perhaps this will work:
(Information taken from this page on MSDN.)
是的,使用
and
对具有相互依赖关系的类型定义进行分组:Yes, use
and
to group type definitions with inter-dependencies:“and”通常适用于相互依赖的类型。也就是说,它适用于所有类型,例如 Mau 所示的可区分联合、类、记录和相互递归函数。
非终止示例:
"and" works generally for types with mutual dependencies. That is, it works for all types, such as discriminated unions, as shown by Mau, classes, records and mutually recursive functions.
Non terminating example: