RFC https://github.com/fsharp/fslang-design/blob/main/preview/FS-1107-Allow-attributes-after-the-module-keyword.md
Allow attributes after the module keyword
Consider:
[<AutoOpen>]
module M =
[<AbstractClass>]
type C() = class end
[<Literal>]
let X = 3
The Literal attribute can be embedded into the let:
[<AutoOpen>]
module M =
[<AbstractClass>]
type C() = class end
let [<Literal>] X = 3 // ✓
Same for the AbstractClass:
[<AutoOpen>]
module M =
type [<AbstractClass>] C() = class end // ✓
let [<Literal>] X = 3
But not the AutoOpen.
module [<AutoOpen>] M = // FS0010: Unexpected start of structured construct in definition. Expected identifier, 'global' or other token.
type [<AbstractClass>] C() = class end // FS0010: Unexpected keyword 'type' in implementation file
let [<Literal>] X = 3
The existing way of approaching this problem in F# is leaving the AutoOpen above the module.
Pros and Cons
The advantages of making this adjustment to F# are
- Consistency -
modules are just specialized types, so placing attributes after the keyword should be allowed as well.
- Conciseness - we can utilize the horizontal space to our advantage, thus scrolling less.
The disadvantage of making this adjustment to F# is having more ways to do the same thing. However, precedence has been already made for types and lets.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions:
#33
I would say that this should be allowed for members as well.
// Not using a module to ensure that the module suffix is not added
type MyList() =
// Fields omitted
[<CompiledName("Map")>]
static member map f l =
// Implementation omitted
Thanks for the suggestion
However I will decline this: what we have works, and the proposed saving is only one line, and the lines become loooong. In balance I don't see a net benefit.
Sure, what we have works, but inconsistent language features are worse than having multiple ways to do the same thing. (Recall: Unification of List, Array, Seq functions in F# 4.0)
Whether the lines become long depends on the length of the name of members and attributes. If they are short enough, they deserve to be combined to utilize more horizontal space.
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
RFC https://github.com/fsharp/fslang-design/blob/main/preview/FS-1107-Allow-attributes-after-the-module-keyword.md
Allow attributes after the module keyword
Consider:
The
Literalattribute can be embedded into thelet:Same for the
AbstractClass:But not the
AutoOpen.The existing way of approaching this problem in F# is leaving the
AutoOpenabove themodule.Pros and Cons
The advantages of making this adjustment to F# are
modules are just specializedtypes, so placing attributes after the keyword should be allowed as well.The disadvantage of making this adjustment to F# is having more ways to do the same thing. However, precedence has been already made for
types andlets.Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions:
#33
I would say that this should be allowed for
members as well.Sure, what we have works, but inconsistent language features are worse than having multiple ways to do the same thing. (Recall: Unification of List, Array, Seq functions in F# 4.0)
Whether the lines become long depends on the length of the name of members and attributes. If they are short enough, they deserve to be combined to utilize more horizontal space.
Affidavit (please submit!)
Please tick this by placing a cross in the box:
(This has sort of been decided for members, but not modules. Module definitions tend to be much shorter than member definitions anyways.)
Please tick all that apply: