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 374353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:23:50+00:00 2026-05-12T14:23:50+00:00

In C#, I can implement a generic interface twice on one class, using two

  • 0

In C#, I can implement a generic interface twice on one class, using two different type-parameters:

interface IFoo<T> { void Foo(T x); }

class Bar : IFoo<int>, IFoo<float>
{
    public void Foo(int x) { }
    public void Foo(float y) { }
}

I would like to do the same thing in F#:

type IFoo<'a> = abstract member Foo : 'a -> unit

type Bar() =
    interface IFoo<int> with 
        [<OverloadID("int")>]
        member this.Foo x = ()

    interface IFoo<float> with 
        [<OverloadID("float")>]
        member this.Foo x = ()

But it gives a compiler error:

This type implements or inherits the same interface at different generic instantiations 'IFoo<float>' and 'IFoo<int>'. This is not permitted in this version of F#.

I can’t find any discussion of this issue on the web. Is such use frowned upon for some reason? Are there plans to allow this in an upcoming release of F#?

  • 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-05-12T14:23:50+00:00Added an answer on May 12, 2026 at 2:23 pm

    Right now I don’t know of plans to allow this.. The feature has been planned and is, at least partially (see comments) implemented in F# 4.0.

    I think the only reasons its currently disallowed are that it’s non-trivial to implement (especially with F# type inference), and it rarely arises in practice (I only recall one customer ever asking about this).

    Given an infinite amount of time and resources, I think this would be allowed (I can imagine this being added to a future version of the language), but right now it does not seem like this is a feature worth the effort of supporting. (If you know a strong motivating case, please mail fsbugs@microsoft.com.)

    EDIT

    As an experiment for the curious, I wrote this C#:

    public interface IG<T>
    {
        void F(T x);
    }
    public class CIG : IG<int>, IG<string>
    {
        public void F(int x) { Console.WriteLine("int"); }
        public void F(string x) { Console.WriteLine("str"); }
    }
    

    and referenced it from F# (with comments suggesting the results)

    let cig = new CIG()
    let idunno = cig :> IG<_>  // type IG<int>, guess just picks 'first' interface?
    let ii = cig :> IG<int>    // works
    ii.F(42)                   // prints "int"
    let is = cig :> IG<string> // works
    is.F("foo")                // prints "str"
    

    so this is what typically happens on this ‘boundary’ stuff with F# – F# can consume this stuff ok, even if you can’t author the same stuff from within the language.

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

Sidebar

Ask A Question

Stats

  • Questions 202k
  • Answers 202k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer string should be lower case or std::string May 12, 2026 at 8:24 pm
  • Editorial Team
    Editorial Team added an answer You don't explititly need the Quartz API for such a… May 12, 2026 at 8:24 pm
  • Editorial Team
    Editorial Team added an answer why do you lookup the parent? maybe use mouseChildren =… May 12, 2026 at 8:24 pm

Related Questions

I'm having a spot of trouble with generics in C#. I have to store
The following code: public interface ISomeData { IEnumerable<string> Data { get; } } public
It looks like I had a fundamental misunderstanding about C++ :< I like the
I have a generic class that I'm trying to implement implicit type casting for.
Background I am using interface-based programming on a current project and have run into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.