Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9022475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:31:10+00:00 2026-06-16T05:31:10+00:00

I have the following code snippet using the reactive extensions: let value : ‘t

  • 0

I have the following code snippet using the reactive extensions:

    let value : 't = ...

    Observable.Create<'t>(fun observer ->
        let subject = new BehaviorSubject<'t>(value)
        let d0 = subject.Subscribe(observer)
        let d1 = observable.Subscribe(subject)
        new CompositeDisposable(d0, d1) :> IDisposable
    )

This works. However if I drop the upcast to IDisposable then the code fails
to compile, citing ambiguous overloads. However CompositeDisposable is an
IDisposable. Why is the type inference engine failing to resolve this? Note I use this pattern almost all the time in C# returning CompositeDisposable from Observable.Create without having to upcast.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:31:12+00:00Added an answer on June 16, 2026 at 5:31 am

    As @kvb said, functions don’t support variance so upcast is required for interfaces and subclasses.

    Here is a small example demonstrating the behavior with subclasses:

    type A() =
        member x.A = "A"
        
    type B() =
        inherit A()
        member x.B = "B"
    
    let f (g: _ -> A) = g()
    
    let a = f (fun () -> A()) // works
    let b = f (fun () -> B()) // fails
    

    If function f is written by you, adding type constraints could help:

    // This works for interface as well
    let f (g: _ -> #A) = g()
    
    let a = f (fun () -> A()) // works
    let b = f (fun () -> B()) // works
    

    Otherwise, you have to do a litle upcast as your example described.

    EDIT: Since F# 6.0, auto-upcasting of interfaces and subclasses is now supported by default.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code snippet: using (SPSite site = new SPSite(this.ListAddress)) { using
I have the following snippet of code (I'm using jQuery 1.4.2): $.post('/Ads/GetAdStatsRow/', { 'ad_id':
I have the following code snippet. I am compiling using the sun studio 12
I have summarized my problem in following code snippet using System; using System.Collections.Generic; using
I have summarized my problem in following code snippet. using System; using System.Collections.Generic; using
I have the following code snippet, that transforms a set of bounds using the
I have one problem when i am using following code snippet String regexString=regexPair.get(paramName); Pattern
In my prism module, I have the following code snippet: using (var manifestResourceStream =
I have following code snippet that i use to compile class at the run
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.