fsharp / fsharp/fslang-suggestions

#langversion

Open
#814 17 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: directives
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

# #langversion

I propose we add `#langversion` to F# scripts.

```fs
#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 `nameof` usable.

```fs

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
1. Ability to use new F# features in script files
2. More consistency with actual F#

The disadvantages of making this adjustment to F# are none that I can think of.

## Extra information

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:
* [x] This is not a question (e.g. like one you might ask on [stackoverflow](http://stackoverflow.com)) and I have searched stackoverflow for discussions of this issue
* [x] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) and believe this is not a duplicate
* [x] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:
* [x] This is not a breaking change to the F# language design
* [x] I or my company would be willing to help implement and/or test this

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the F# Interactive script behavior shown in the issue and review the discussion around adding #langversion. Determine how scripts should select language versions and verify that a script using nameof can enable preview features without creating a project.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.