baronfel / fsharp-lang-testbed

0 stars 0 forks source link

Add anonymous modules #2

Open baronfel opened 7 years ago

baronfel commented 7 years ago

Idea 10012488: Add anonymous modules

Status : declined

Submitted by Alex Corrado on 10/1/2015 12:00:00 AM

1 votes

Often, I find myself writing little private modules to provide some syntactic sugar for a type that I'm using heavily in a file. For instance, take this method for quoting an F# function into a LINQ Expression Tree from http://stackoverflow.com/a/23146624/578190. It would be nice if I could write it like this: open System.Linq.Expressions open module = type Expression with static member Lambda(e:Expression<_>) = e The above construct would be equivalent to this: module private SomeGeneratedNameIDontCareAbout = type Expression with static member Lambda(e:Expression<_>) = e open SomeGeneratedNameIDontCareAbout Note that the module is implicitly private; it effectively has no name, so there is no way to reference its members outside the scope in which it is open'd. The open module = syntax is just my random suggestion :)

baronfel commented 7 years ago

Comment by Alex Corrado on 10/1/2015 1:03:00 PM

A colleague just pointed out that you can do this: [] module private __ = ... Not quite as pretty, but adequate. Feeling a little silly, I withdraw my suggestion.