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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:30:05+00:00 2026-06-18T04:30:05+00:00

I have a vexing error. type Animal = abstract member Name : string type

  • 0

I have a vexing error.

type Animal =

    abstract member Name : string

type Dog (name : string) =

    interface Animal with

        member this.Name : string =
            name

let pluto = new Dog("Pluto")
let name = pluto.Name

The last line, specifically “Name” generates a compiler error saying that “the field, constructor or member ‘Name’ is not defined”.

The workaround I’ve used is to write

let name = (pluto :> Animal).Name

However this is very annoying and creates a lot of visual noise. Is there something one can do in F# to just be able to resolve Name without telling the compiler explicitly that Name is a derived member from the Animal 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-06-18T04:30:07+00:00Added an answer on June 18, 2026 at 4:30 am

    In F#, when you implement an interface, it’s an equivalent of explicit interface implementation in C#. That is, you can call the method through the interface, but not directly through the class.

    F# reference article about interfaces suggests adding a method that does the upcasting to the type:

    type Dog (name : string) =
    
        member this.Name = (this :> Animal).Name
    
        interface Animal with
            member this.Name : string = name
    

    Or, as suggested by Daniel, you can do it the other way around, which means you can avoid that cast:

    type Dog (name : string) =
    
        member this.Name = name
    
        interface Animal with
            member this.Name : string = this.Name
    

    Also, the .Net convention for interface names is to start them with I, so your interface should be called IAnimal.

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

Sidebar

Related Questions

ASP.NET 4.0 Need some help with this vexing HTTP POST problem - I have
Have: [DllImport(OpenAL32.dll)] static extern void alcOpenDevice(char*[] devicename); Wanna send the name to this function
Because of the most vexing parse, if you have a private member definition in
have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
A mysql query is vexing me. I have some javascript that lets users assign
This seems like such a trivial question to ask, but it's been vexing me
have defined a Java Interface with the annotation @WebService Compiled the code which went
Have been trying to figure this problem out for a while now and was
Newbie Warning I have a simple but vexing problem trying to disable an NSButton.

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.