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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:45:51+00:00 2026-05-15T15:45:51+00:00

Is it possible to implement friend function and friend class (as in c++) in

  • 0

Is it possible to implement friend function and friend class (as in c++) in F#?

Update:
Since there is no friend function/class in f#, and friend is not even a reserved keyword for future expansion, I’m wondering is there any problems with the friend mechanism in F# that make the developers to decide not to implement it?
(such as in “protected” access modifier).

Suggestion 1: Brian, signature file –
I don’t think that this thing work properly. If you have a closure (e.g. lambda expression in A, which is a different object than the instance of A) that evaluate B.X , it’s won’t work

Suggestion 2: Massif (+Mitya0), InternalsVisibleTo –
It’s not clear to me, Are you writing this in the second class or it expose the class to the entire assembly?

  • 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-15T15:45:51+00:00Added an answer on May 15, 2026 at 3:45 pm

    Note that you can use signature files to mimic friend.

    If you want A to be a friend of B, so A can access internals of B that others cannot see, you can do e.g.

    // File1.fs
    type B() =
        let x = 42  // private field
        member this.X = x // public getter
    
    type A() =
        member this.PeekInto(b : B) =
            b.X
    

    but also have

    // File1.fsi
    type B = 
        new : unit -> B
        // do not expose X in the signature
    
    type A = 
        new : unit -> A
        PeekInto : B -> int
    

    and now A‘s implementation can see B.X but the sequel of the program cannot see B.X.

    Signature files are pretty awesome for creating arbitrary encapsulation boundaries.

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

Sidebar

Related Questions

Is it possible to implement a timeout in an inputstream.read() function from a BluetoothSocket
Is that possible to implement the update of my own p2 enabled RCP application
Is it possible to implement a bi-directional tree in a case class. This seems
Possible Duplicate: How would you implement tail efficiently? A friend of mine was asked
Is it possible to implement some kind of timeout (time limit) for fork using
Is it possible to implement a Facebook Subscribe Button for a Facebook Page rather
Is it possible to implement navigation using jquery ui tabs instead of standard tabs
It is possible to implement a feature that allows users to watch videos as
Is it possible to implement McCarthy's amb -operator for non-deterministic choice in C#? Apparently
It's possible to implement INotifyCollectionChanged or other interface like IObservable to enable to bind

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.