fsharp / fsharp/fslang-suggestions

Remove 'no module' restriction on .fsx files

Open
#1,077 8 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

approved-in-principle area: syntax
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

Remove restriction that main .fsx file mustn't define a module

Dotnet fsi fails if the main .fsx file defines a module:

module Hello
printfn "Hello world"
> dotnet fsi Hello.fsx
Hello.fsx(3,1): error FS0010: Unexpected start of structured construct in definition. Expected '=' or other token.

What is allowed is

module Hello =
    printfn "Hello world"

or just

printfn "Hello world"

A full-fledged F# project however does not have this restriction.

This makes it impractical to experiment with interactive workspaces, because one always has to remove the module definition before testing a single file with fsi and then put it back if one wishes to reference the file from somewhere else.

I would therefore propose to remove this 'no module' restriction.

This is based on report: https://github.com/dotnet/fsharp/issues/11699

Pros and Cons

The advantages of making this adjustment to F# are

  • makes it more convenient for people to run files interactively
  • makes interactive mode behave same as normal projects.

The disadvantages of making this adjustment to F# are

  • none

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S

Related suggestions: none that I know

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • 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:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this

For Readers

If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.

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 by reproducing the restriction with dotnet fsi Hello.fsx and the module-based example shown in the issue. Identify the compiler or FSI entry point that rejects a top-level module, then verify that the file runs without the workaround while existing script forms continue to work.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.