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

  • Home
  • SEARCH
  • 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 6723133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:31:56+00:00 2026-05-26T09:31:56+00:00

You probably know the Adapter example below : type Cat() = member this.Walk() =

  • 0

You probably know the Adapter example below :

type Cat() =
member this.Walk() = printf "Cat walking"

type Dog() =
    member this.Walk() = printf "Dog walking"


let inline walk (animal : ^T ) =
    (^T : (member Walk : unit -> unit) (animal))

let cat = new Cat()
let dog = new Dog()

walk cat
walk dog

a different version of walk is compiled statically for the Cat and Dog classes.

Then I tried the following :

type Cat = { Name : string }
type Dog = { Name : string }

let inline showName (animal : ^T ) =
    let name = (^T : (member Name : string) (animal))
    printf "%s" name

let cat = { Name = "Miaou" } : Cat
let dog = { Name = "Waf" } : Dog

showName cat
showName dog

but I get the following compilation error :

The type 'Dog' does not support any operators named 'get_Name'

and the same for class Cat.

But when exploring the generated class for both records, it actually contains this get_Name method for the generated Name property.

Is there a different syntax to access Records fields in statically resolved generics, or is it a F# compiler limitation ?

  • 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-26T09:31:57+00:00Added an answer on May 26, 2026 at 9:31 am

    Your showName function implementation applies to standard .NET classes having Name property. Although neither Cat nor Dog are such; instead both are of F# record type.

    Despite accessing a record field looks literally similar to accessing a standard class property for F# type inference these two cases are completely different.

    You have defined two record types with non-unique field name Name; access to the field Name of instance cat of record type Cat is cat.Name, similarly for dog it is dog.Name. But when you try showName cat or showName dog compiler complains on absense of Name property in these record types, which is expected behavior, because there is no such property in these records.

    Addendum:
    To illustrate my point I did a slight modification to the original code adding property Nickname to both Cat and Dog:

    type Cat = { Name : string } member x.Nickname = x.Name
    type Dog = { Name : string } member x.Nickname = x.Name
    
    let inline showName (animal : ^T ) =
        let name = (^T : (member Nickname : string) (animal))
        printfn "%s" name
    
    let cat = { Name = "Miaou" } : Cat
    let dog = { Name = "Waf" } : Dog
    
    showName cat
    showName dog
    

    This will happily work.

    Take a notice of signature of modified classes: it is now

    type Cat =
      {Name: string;}
      with
        member Nickname : string
      end
    

    And finally, the compiler will forbid having both a field and a property of a record type similarly named with The member 'Xyzzy' can not be defined because the name 'Xyzzy' clashes with the field 'Xyzzy' in this type or module message.

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

Sidebar

Related Questions

This is one of those I probably should know this, but I don't questions.
This is something stupid I probably should know, but Googling fails me: When compiling
I should probably know this by now, but what, if any is the difference
I should probably know this already, but I'm not sure and I don't see
I have this question you probably know the answer... My app is already functional
As those who have worked on such a project you probably know this site:
As many of you probably know, online banks nowadays have a security system whereby
As you probably know, Derek Sivers is the guy who created CD Baby and
Most of you probably know the following problem: You edit an HTML, view the
I think I probably know that the most common suggestion will be change the

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.