Using a custom operator of a calculation expression inside a matching operator

Now I am experimenting with F # evaluation expressions. The general idea is to return a control mechanism for the actions performed after each step of the recursive assembly of a function call from a calculation expression. The whole example can be seen here .

Using the 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 a compile-time error on unhandled: the user operation may not be used in conjunction with 'use', 'try / with', 'try / finally', 'if / then / else' or 'match' in this calculation expression.

Is there any way to use custom operators inside matching operators?

+4
1

, actor, Unhandled - , , , return!

, , - :

match msg with
| "stop" -> return 0
| "unhandled" -> return! Unhandled
| x -> 
    mailbox.Sender() <! x
    return! loop ()   
+1

Source: https://habr.com/ru/post/1611198/


All Articles