我想编写以下代码:
let someAsync () = async {
if 1 > 2 then return true // Error "this expression is expected to have type unit ..."
// I want to place much code here
return false
}
F# 出于某种原因认为我需要这样写:
let someAsync () = async {
if 1 > 2 then return true
else
// Much code here (indented!)
return false
}
在后一种情况下,不会产生错误消息。但在我看来,这两段代码是等价的。有没有机会避免不必要的嵌套和缩进?
UPD。我要问的确实是可能的!请看示例,请参阅真实世界示例部分
我将引用代码:
let validateName(arg:string) = imperative {
if (arg = null) then return false // <- HERE IT IS
let idx = arg.IndexOf(" ")
if (idx = -1) then return false // <- HERE IT IS
// ......
return true
}
因此,有可能,唯一的问题是是否可以async
通过扩展模块或其他方式以某种方式实现 in 。