I suggest we ...

extend ComputationExpression builders with Map : m<'a> * ('a -> 'b) -> m<'b>

In many scenarios computation expressions could be executed way more efficiently when having just a little more information.

The typical use-case for that would be something like

async {
let! a = something
return 2*a
}

which currently gets translated to:
async.Bind(something, fun a -> async.Return(2*a))

By monad laws (borrowed from haskell here) this must be equal to:
async.Map(something, fun a -> 2*a)

In many scenarios the latter can be implemented with a lot less overhead, so in my opinion it would be profitable to allow users to provide this "shortcut".

8 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Georg Haaser shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...

F# Language

Feedback and Knowledge Base