olarak adlandırılır Kombinasyonu bu düz ileri Maybe
monad uygulamak için çalıştı. Bu nedenle, temel ifade Nothing
ise, tüm ifade Nothing
olarak değerlendirilir. Ben foobar
beklenenF # hesaplama ifadesi ne zaman
type Maybe<'a> =
| Just of 'a
| Nothing
type MaybeBuilder() =
member this.Combine ((first, second) : Maybe<'a> * Maybe<'b>) : Maybe<'b> =
printfn "Combine called"
match first with
| Nothing -> Nothing
| _ ->
match second with
| Nothing -> Nothing
| _ as a -> a
member this.Zero() = Just()
member this.Bind((m, f) : Maybe<'a> * ('a -> Maybe<'b>)) =
printfn "Bind called"
match m with
| Nothing -> Nothing
| Just a -> f a
let MaybeMonad = MaybeBuilder()
let foobar =
MaybeMonad {
let! foo = Just "foo"
Just 1
Nothing
}
Just "foo" >>= fun foo -> Combine(Just 1, Nothing)
çevrilmesi, ancak Combine
çağrılmadı.
Ve bu makaleyi şu güzel makale dizisiyle takip edin: https://fsharpforfunandprofit.com/series/computation-expressions.html – rmunn