次のコードを書きたい:
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
}
後者の場合、エラー メッセージは生成されません。しかし、私の見解では、両方のコードは同等です。不必要な入れ子やインデントを回避できる可能性はありますか?
アップデート。私が求めていることは確かに可能です!例を見てください。実世界の例のセクションを参照してください。
コードを引用します:
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
モジュールへの拡張などを介して、何らかの形で実装できるかどうかです。