後で計算式の正規メソッドの 1 つで使用できる計算式でメソッドまたはスタンドアロン関数を作成することは可能ですか?
私はこのようなものが欲しい:
type FormletBuilder(ctx : HttpContext) =
let get_int =
match Int32.TryParse (ctx.Request.["foo"]) with
| (true, n) -> Some n
| _ -> None
//similar definitions for get_date, get_non_empty_str, etc...
member x.Bind (read : 'a option, f : 'a -> option 'a) =
match read with
| Some x -> f(x)
| None -> None
member x.Return (obj) = Some obj
member x.Zero () = None
let person = formlet ctx {
let! id = get_int "id"
let! name = get_non_empty_str "fullname"
return Person(id, name)
}
get_int
しかし、コンパイラはそれが定義されていないと不平を言います。