Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
I propose we add
#langversion "preview" let x = () in nameof x;; // :)
The existing way of approaching this problem in F# is creating an entire project just to make scripts with
Microsoft (R) F# Interactive version 10.6.0.0 for F# 4.7 Copyright (c) Microsoft Corporation. All Rights Reserved. For help type #help;; > let x = () in nameof x;; // :( let x = () in nameof x;; // :( --------------^^^^^^ stdin(1,15): error FS0039: The value or constructor 'nameof' is not defined. >
Pros and Cons
The advantages of making this adjustment to F# are
The disadvantages of making this adjustment to F# are none that I can think of.
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: None
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
It's very easy to implement this as a new
#langversion "preview" let x = 12 let name() = nameof x #langversion "4.7" printfn "%s" (name ())
What should happen? The
This is also even more difficult in a Jupyter scripting environment, where you might have tens of cells, and you can reference things defined in any other cells (not just those defined above where you're working!). You can imagine the above script split into two arbitrary cells in a very large notebook - what happens to other cells if you set the LangVersion to a lower language version somewhere in the notebook?
Questions like this didn't yield any satisfying answers, hence it was not implemented.
@cartermp Why is it even that complicated? Hash directives already indicate that it is something "static". Therefore in a regular script file the "last" one would win. In an interactive environment, you would just switch the compiler settings for new code as there is really nothing else you can do.
Isn't this already similar to when you use the current directory and change it via
Alternatively, we can just make version downgrades fail or ignore them silently.
It's complicated mostly because the notion of switching one's effectively language version interactively isn't what it was originally designed for. While you can certainly do this in a project file in tools like VS and have the editor react accordingly, this isn't interactive - it's akin to rebuilding again, just at design-time. So it's more like restarting an FSI session and reloading everything than an interactive switch in the current tooling.
The majority case is easy here; like almost all other
Additionally, there's no good way to handle script IntelliSense for this. Currently,
I see why intellisense might be a bit hard to do correctly. I don't get why Jupyter is so special - I guess I'm not familiar enough with their workflow - but in any case thanks for the details! So I assume in the end this feature is just not an 'S' but a lot of work and includes some risks and at this point it is debatable if it is even worth the effort.
As a rule, we want to provide tools that encourage developers to adopt the latest builds eagerly. This feature was designed to be in support of that goal.
The primary intent of the languageversion switch is to enable a developer who is working on a project using a stable version of F# to peg that project to that specific version of F#, and so not introducing dependencies on newer features of F# until the project team has declared an interest in completing the transition to the latest language features.
The secondary intent of the feature was to enable developers to kick the tyres on preview language features by explicitly selecting preview.
Scripting developers can use the command line switch to constrain their scripts to a down-level language version if they so choose. Although the global.json file is the preferable choice for that. Scripts that self-adapt to the ambient fsi language version is not a scenario that we currently target.
@Happypig375 we or someone else can probably add UI to enable preview in VS Fsi. That is a good proposal. I'm kind of sorry I hadn't thought of it already, however, we have only recently decided that we will preview F# 5.0 language features in the 4.7 compiler the previous plan was to restrict them to dotnet 5.0 previews.
I hope this alleviates your concerns