I suggest we ...

Allow types to behave also like modules.

I find this kind of coding annoying

module Foo =
type T = { a:int, b:int }
let xxx t = t.a
let yyy t = t.b

it would be much more compact and have less noise in the type system to allow

type Foo =
{ a:int, b:int }
with
let xxx t = t.a
let yyy t = t.b

So you can do

{ a = 10; b = 20 } | Foo.xxx

1 vote
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Brad Phelan shared this idea  ·   ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Don Syme commented  · 

        As pointed out below, adding static members to types is close to what you want.

      • Anonymous commented  · 

        The following works:

        type Foo =
        { a:int; b:int }
        with
        static member xxx t = t.a
        static member yyy t = t.b

      F# Language

      Feedback and Knowledge Base