fsprojects / FSharp.Control.Reactive

Extensions and wrappers for using Reactive Extensions (Rx) with F#.
http://fsprojects.github.io/FSharp.Control.Reactive
Other
284 stars 58 forks source link

try ... with in observe causes compile error #122

Closed kumaryu closed 4 years ago

kumaryu commented 5 years ago

Description

Exception handlers in observe computation expression cannot be compiled.

Repro steps

open System
open FSharp.Control.Reactive.Builders

let errorObservable () =
    observe {
        try
            InvalidOperationException() |> raise
        with
        | :? InvalidOperationException ->
            printfn "InvalidOperationException raised"
    }

Expected behavior

It should be compiled.

Actual behavior

This runtime coercion or type test from type
    'a    
 to 
    InvalidOperationException    
involves an indeterminate type based on information prior to this program point. Runtime type tests are not allowed on some types. Further type annotations are needed.

Known workarounds

ObservableBuilder has

member __.TryWith(m: IObservable<_>, h: #exn -> IObservable<_>) = Observable.Catch(m, h)

but it intended for h: exn -> IObservable<_> ?