I suggest we ...

Implement monadic getters and setters

The get/set syntax for F# is very cool, but it has an issue: sometimes, the property we would like to get and set is only available through a workflow/monad, like the async workflow.

Thus, I would like to alter the typechecking rules for getters and setters. This is what they are right now (pseudocode) for the Async monad:

Property x : Async<'a>
get : unit -> Async<'a>
set : Async<'a> -> unit

IndexedProperty x : 'k -> Async<'v>
get : 'k -> Async<'v>
set : 'k -> Async<'v> -> 'unit

This is what I would like to see made possible:

type Id<'a> = 'a

Property x : Async<'a>
get : unit -> Async<'a>
set : 'a -> Async<unit>

IndexedProperty x : 'k -> Async<'v>
get : 'k -> Async<'v>
set : 'k -> 'v -> Async<unit>

3 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Anonymous shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

2 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Don Syme commented  ·   ·  Flag as inappropriate

    I am very sympathetic to this proposal. However, please note that the items would likely not be "proper" .NET properties since those are required to have "unit" return type on the setter method.

  • Mauricio Scheffer commented  ·   ·  Flag as inappropriate

    Interesting, could you post a snippet illustrating how the current syntax/typechecking is insufficient, and how this suggestion would make it better?

F# Language

Feedback and Knowledge Base