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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:38:20+00:00 2026-06-04T11:38:20+00:00

What is the correct way to handle this situation. I have one method in

  • 0

What is the correct way to handle this situation. I have one method in my F# class DogTree that should fulfill the requirement of implementing a Bark() method for both interfaces.

type ITree =
    interface
        abstract Bark : unit -> unit
        abstract Grow : unit -> unit
    end

type IDog =
    interface
        abstract Bark : unit -> unit
        abstract ChaseCar : unit -> unit
    end

type TreeDog = 
   // so the "and" syntax below doesn't work - what is the correct way to handle?
   interface IDog and ITree with
      member this.Bark() = printfn "Bark" 
  • 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-04T11:38:23+00:00Added an answer on June 4, 2026 at 11:38 am

    You can delegate to a common implementation:

    type TreeDog = 
      interface IDog with
        member this.Bark() = printfn "Bark" 
      interface ITree with
        member this.Bark() = (this :> IDog).Bark()
    

    Or, more appropriately:

    type TreeDog = 
      member this.Bark() = printfn "Bark"
      interface IDog with
        member this.Bark() = this.Bark() 
      interface ITree with
        member this.Bark() = this.Bark()
    

    (Note that this defines an extra method in the class named Bark, that is used as the implementation for both interfaces.)

    If you declare a primary constructor in your class, you can use this instead:

    type TreeDog() = // primary constructor
      let bark() = printfn "Bark" // this member is private
      interface IDog with
        member this.Bark() = bark()
      interface ITree with
        member this.Bark() = bark()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the situation. I have a base class which implements a method that accepts
Is this the correct way to do it? <a id=load href=# class=btn load onclick=request(this);
What is the correct way to handle an orientation change when using Fragments? I
What is the correct way to do conditional formatting in Django? I have a
Is this the correct way to obtain the most negative double in Java? double
Apple have conveniently created a callback method that allows you to check that the
On this site I have a situation where a user might need to be
How should I handle a custom property in a situation where I use partial
I have a class that has no default constructor or assignment operator so it
I am looking for the correct way to handle a return statement with a

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.