intrinsic type extension across file boundries #16442
Replies: 3 comments 1 reply
-
Did you read the error message carefully, and try to do what it suggested? :) |
Beta Was this translation helpful? Give feedback.
-
Yes I did read the error message :) To clarify the question since you do point this out: The point is NOT to make an extrinsic type extension. Intrinsic type extensions are compiled into the definition of the original type definition and have access to all the If I do what the error message says then I'll have an extension method inside the Module that can only access public and internal fields, NOT In fact, I came across some code examples recently from several years ago in which this apparently worked at one time and the author suggested this was a way of supporting the same feature as partial classes in C#. This author was very through in other writings regarding F# concepts, and so I am assuming he tested this before writing the blog post. I had thought this didn't work (until reading the above blog post) and this is one of the reason's I don't do intrinsic type extensions in my code bases because they don't work in an orthogonal way as I would expect. I really don't like using a feature or explaining one to my junior staff that has a major gotcha that jumps up and bits you for no apparent reason. And from looking at some of the compiler code base so far, it's not clear why we don't do this. Thus, the question, we must have had a reason for this decision. :) |
Beta Was this translation helpful? Give feedback.
-
It's been decided long time ago really, spec states it explicitly in 8.12:
|
Beta Was this translation helpful? Give feedback.
-
I can't for the life of me remember why it was decided that we can't have intrinsic type extensions across file boundaries?
What I want to know is why this isn't supported:
File1.fs
File2.fs
These would both be compiled into the same assembly and of course are in the same namespace.
Interestingly if the following code is in the same file this actually works as I would expect:
SingleFile.fs
So I would expect that a code file that would exist between File1.fs and File2.fs shouldn't see anything defined in File2.fs. If we supported this, then we could support code gen scenarios better.
Beta Was this translation helpful? Give feedback.
All reactions