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?
Note that you can use signature files to mimic friend.
If you want
Ato be a friend ofB, soAcan access internals ofBthat others cannot see, you can do e.g.but also have
and now
A‘s implementation can seeB.Xbut the sequel of the program cannot seeB.X.Signature files are pretty awesome for creating arbitrary encapsulation boundaries.