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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:13:06+00:00 2026-05-23T23:13:06+00:00

Given the following CRTP type in C#: public abstract class DataProviderBase<TProvider> where TProvider :

  • 0

Given the following CRTP type in C#:

public abstract class DataProviderBase<TProvider>
    where TProvider : DataProviderBase<TProvider> { }

How would I get its generic type definition in F#?

let typeDef = typedefof<DataProviderBase<_>>

yields the error:

Type constraint mismatch when applying the default type ‘DataProviderBase<‘a>’ for a type inference variable. The resulting type would be infinite when unifying ”a’ and ‘DataProviderBase<‘a>’ Consider adding further type constraints

In C#, it would be:

var typeDef = typeof(DataProviderBase<>);

UPDATE

I found a workaround:

[<AbstractClass>]
type DummyProvider() =
  inherit DataProviderBase<DummyProvider>()

let typeDef = typeof<DummyProvider>.BaseType.GetGenericTypeDefinition()

Is there another way to do it, without the extra type?

  • 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-23T23:13:06+00:00Added an answer on May 23, 2026 at 11:13 pm

    I think this is actually a very good question. I didn’t find a better workaround for this.
    You can slightly simplify your workaround by using typedefof like this:

    let typeDef = typedefof<DataProviderBase<DummyProvider>>
    

    TECHNICAL DETAILS

    The problem is that F#’s typedefof<'T> is just an ordinary function that takes a type argument (unlike typeof in C#, which is an operator). In order to call it, you need to give it an actual type and the function will then call GetGenericTypeDefinition under the cover.

    The reason why typedefof<option<_>> works is that F# specifies a default type as an argument (in this case obj). In general, F# chooses the less concrete type that matches the constraints. In your case:

    DataProviderBase<_> will become DataProviderBase<DataProviderBase<_>> and so on.

    Unless you define a new type (as in your workaround), there is no concrete type that could be used as a type argument of typedefof<...>. In this case, the defaulting mechanism simply doesn’t work…

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

Sidebar

Related Questions

its templates again ;-) Given the following template member functions and CRTP class: template<typename
Given the following classes: class Department { public String Name { get; set; }
Given the following code: public class SomeClass { private boolean shouldBlock = false; private
Given the following code : import java.io.*; public class Main { public static void
Given the following example (using JUnit with Hamcrest matchers): Map<String, Class<? extends Serializable>> expected
Given the following two ways of defining a class method in Ruby: class Foo
Given the following code, is there a way I can call class A's version
Given following HTML <select name="IBE1$IBE_NurFlug1$ddl_Abflughafen" id="IBE1_IBE_NurFlug1_ddl_Abflughafen" class="dropdownlist" style="width: 99%;"> <option value="Antalya;TR">Antalya</option> <option value="Berlin;DE">Berlin</option> <option
given following html <input id=IBE1_IBE_NurFlug1_RadioButtonList1_0 name=IBE1$IBE_NurFlug1$RadioButtonList1 value=Blue type=radio> <label for=IBE1_IBE_NurFlug1_RadioButtonList1_0>Blue</label> <input id=IBE1_IBE_NurFlug1_RadioButtonList1_1 name=IBE1$IBE_NurFlug1$RadioButtonList1 value=Green
Given the following : // get the list of the players , in order

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.