fsharp / fslang-suggestions

The place to make suggestions, discuss and vote on F# language and core library features
345 stars 21 forks source link

Allow type declaration with `sig` on code/script files #1382

Closed noralambda closed 2 months ago

noralambda commented 2 months ago

I propose we ... (describe your suggestion here)

sig could be used for type declaration in script and code files.

Examples:

sig foo : int -> float -> string in
let foo a b = 
    //...
sig x : Person in
let x = {Name=10; Age=5}
type Foo() = 
    sig member A : () -> 'X in
    member _.A () = // ...

    sig member B : 'X in
    member val B = // ...

in should be optional on Recursive Modules.

I feel this syntax for class member signature is weird. Help?

Multiple declaration should be considered error:

sig bar : float -> float -> int in
let bar a (b:float) = // Error
    // ...

Pros and Cons

The advantages of making this adjustment to F# are

Code becomes easier to read and reason about

Extra information

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

Related suggestions: (put links to related suggestions here)

341

Affidavit (please submit!)

Please tick these items by placing a cross in the box:

Please tick all that apply:

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.

T-Gro commented 2 months ago

Duplicate of https://github.com/fsharp/fslang-suggestions/issues/341 , which was closed as "probably not".

T-Gro commented 2 months ago

Closing comment: https://github.com/fsharp/fslang-suggestions/issues/341#issuecomment-1506752584

vzarytovskii commented 2 months ago

Yeah, I think it's essentially the same. Also, personally don't like adding another keyword (which is quite unfamiliar), val would've been better (which was also rejected). I am going to close this one.

@dsyme please reopen if your opinion on this changed.