Right now I'm experimenting with F# computation expressions. General idea is to return control mechanism to drive actions executed after each step of recursive function call build from computation expression. Whole example can be seen here.
Using following example:
let rec loop () =
actor {
let! msg = m.Receive ()
match msg with
| "stop" -> return 0 // expected result: Return (0)
| "unhandled" -> unhandled // expected result: Unhandled
| x ->
mailbox.Sender() <! x
return! loop () // expected result: (Become(fun m -> loop ()))
}
loop ()
Unfortunately this ends with compile time error on unhandled: A custom operation may not be used in conjunction with 'use', 'try/with', 'try/finally', 'if/then/else' or 'match' operators within this computation expression.
Is it possible in any way to use custom operators inside match statements?
unhandled? And - assuming its of the right type - why don't you usereturn` orreturn!as well? - Random Devunhandledis a custom operator. In general Return and ReturnFrom are able to return discriminated union of typeReturnorBecomedepending on, if expression is a value or recursive function call. This DU is later used to apply additional logic. What I wanted to do, was to add additional DU typeUnhandledthat has another kind of logic applied. - Bartosz Sypytkowski