fsharp / fsharp/fslang-suggestions

Static members of [<AutoOpen>] tagged class to be directly available as the functions of the class-containing module

Open
#1,255 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

Imagine we have class with static members with AutoOpen attribute in the module. Currently if we open the module the members are instantly added to the scope, however for calling those members without module opening we have to dot into the type name itself.
I propose we make it possible to access the static members of the class tagged with AutoOpen through dot as the module level functions.

The existing way of approaching this problem in F# is to dot through type name.

The advantages of making this adjustment to F# are more consistent static member access and flexible usage of class static member benefits.

The disadvantages of making this adjustment to F# are - some issues with name shadowing may arise, but they will appear anyway if we open the module.

## Extra information
I'm implementing the structure of calls to some web api which endpoints are separated into the number of categories, with specific settings for each category. I found that the easiest approach would be to have the hierarchy of modules with some settings as module mutable parameters and the api calling functions as module-internal class static members, because I need optional parameters of class members to represent the similar of endpoints. This approach seem to work, but for accessing endpoint function I have to dot into Type name after module name (which represents category) even though type is marked as AutoOpen. Which I'd like to avoid.

Related suggestions: (put links to related suggestions here)

## Affidavit (please submit!)

Please tick this by placing a cross in the box:
* [+] This is not a question
* [+] 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
* [+] 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 :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue does not identify implementation files, tests, or compiler entry points. Start by locating the F# compiler handling of AutoOpen modules and static member lookup; done would mean the proposed access works without opening the module while preserving the described existing behavior.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.