嵌套布尔测试的F#计算表达式?

编程入门 行业动态 更新时间:2024-10-22 16:44:08
本文介绍了嵌套布尔测试的F#计算表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我认为我对F#monad(工作流)有足够的了解,我在代码中看到了一些可以实现它们的地方.

I think I've got enough understanding of F# monads (workflows) that I see a few places in my code where implementing them makes sense.

例如,我有一个带有多个嵌套if/thens的函数,即该函数仅在数据沿途通过某些测试"的情况下才继续.

For example, I've got a function with multiple nested if/thens, i.e. the function should continue only so long as the data pass certain "tests" along the way.

我对也许"单子很熟悉,但是在我看到的所有示例中,它都被编码为对let!绑定进行操作,而我并没有这样做.我希望有人可以为我提供一个为嵌套布尔测试而不是let绑定量身定制的也许"工作流的示例.

I'm familiar with the "maybe" monad, but in all the examples that I've seen, it's coded to operate on let! bindings, which I'm not doing. I'm hoping that someone can provide me with an example of the "maybe" workflow tailored for nested Boolean tests, not let binds.

推荐答案

我提供了一个有条件的工作流来响应类似的问题.我将其复制到此处,以供参考.

I offered up a conditional workflow in response to a similar problem. I'll copy it here, for reference.

module Condition = type ConditionBuilder() = member x.Bind(v, f) = if v then f() else false member x.Return(v) = v let condition = ConditionBuilder() open Condition let eval() = condition { // do some work do! conditionA // do some work do! conditionB // do some work do! conditionC return true }

您可以在对我的上一个答案的评论中看到,并非所有人都是粉丝.但这仍然很有趣.

As you can see in the comments to my previous answer, not everyone's a fan. But it's interesting nonetheless.

更多推荐

嵌套布尔测试的F#计算表达式?

本文发布于:2023-11-17 03:09:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608596.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   布尔   表达式   测试

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!