Skip to content

Improve Indentation Rules for Generic Signatures #504

@cloudRoutine

Description

@cloudRoutine

Currently the compiler allows for some interesting ways to write generic signatures

open System

    module Z =
        type Alpha< ^b, ^a 
    when ^     a    :  (member Name:string)
and    ^a:        (member Zip
   : ^b when
^b : struct   )
and             ^a
:                 (static member(+)
    :    'a * 'a 
-> 'a 
) 
         > () = 
            member inline __.X = ()
        with  
        static member inline Y = ()

Since this flies flagrantly in the face of the indentation rules, it'd be nice to fix this for the sake of consistency at the least.

This gives an indentation warning on the ( before static

type TypeWithALongName< ^a 
    when ^a:(static member(+):'a * 'a -> 'a )
    and  ^a:(static member(-):'a * 'a -> 'a )            
    and  ^a:(static member(*):'a * 'a -> 'a )            
    and  ^a:(static member(/):'a * 'a -> 'a )            
    > =
    static member inline X = ()

To fix the warning you have to indent this far

type TypeWithALongName< ^a 
                        when ^a:(static member(+):'a * 'a -> 'a )
                        and  ^a:(static member(-):'a * 'a -> 'a )            
                        and  ^a:(static member(*):'a * 'a -> 'a )            
                        and  ^a:(static member(/):'a * 'a -> 'a )            
    > =
    static member inline X = ()

The former seems like it would work based on the typical indentation approach of needing to be indented one space further than the start of the encompassing construct e.g.

let fn x y = fun z ->
 x * y * z

Pros and Cons

The advantages of making this adjustment to F# are ...

  • indentation consistency

The disadvantages of making this adjustment to F# are:

  • potential to break some horribly formatted code
  • more complex syntax parsing

Extra informtion

Estimated cost : M

Related suggestions:

Affadavit (must be submitted)

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 would be willing to help implement and/or test this
  • I or my company would be willing to help crowdfund F# Software Foundation members to work on this

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions