fsharp / fslang-design

RFCs and docs related to the F# language design process, see https://github.com/fsharp/fslang-suggestions to submit ideas
518 stars 144 forks source link

Create FS-1129-shorthand-anonymous-unary-functions #710

Closed tboby closed 10 months ago

tboby commented 1 year ago

This is just a starting point for https://github.com/fsharp/fslang-suggestions/issues/506 with a basic proof of concept implementation found at https://github.com/dotnet/fsharp/pull/13907

kerams commented 1 year ago

Is intra-assembly closure reuse feasible?

let r1: Record = ...
let r2: Record = ...
let r1x = r1 |> Option.map _.x
let r2x = r2 |> Option.map _.x

There should ideally be only one generated closure per property on type in an assembly, and it could be given a descriptive name.

vzarytovskii commented 1 year ago

Is intra-assembly closure reuse feasible?

let r1: Record = ...
let r2: Record = ...
let r1x = r1 |> Option.map _.x
let r2x = r2 |> Option.map _.x

There should ideally be only one generated closure per property on type in an assembly, and it could be given a descriptive name.

Behaviour should be no different to how full lambda works now, since we just rewrite _.Prop to regular lambda in untyped ast.

T-Gro commented 1 year ago

But even the full lambda as of now produces duplicates for identical operations. https://sharplab.io/#v2:DYLgZgzgPg9gDgUwHYAIDKBPCAXBBbAWAChjjgFsUAnARgA9qaUBeRlKAPhQHk5sBLGEgB0eAIZwUACjABXVAwC0XOsIAqMNNir8kAcykBKQ2QrUATAyrmWF9l14ChoidLkKUylKo1ad+o0MgA==

I believe the comment from @kerams is valid && orthogonal => might be worth a separate suggestions for the optimizer to de-duplicate identical lambda-generated classes.

vzarytovskii commented 1 year ago

But even the full lambda as of now produces duplicates for identical operations. https://sharplab.io/#v2:DYLgZgzgPg9gDgUwHYAIDKBPCAXBBbAWAChjjgFsUAnARgA9qaUBeRlKAPhQHk5sBLGEgB0eAIZwUACjABXVAwC0XOsIAqMNNir8kAcykBKQ2QrUATAyrmWF9l14ChoidLkKUylKo1ad+o0MgA==

I believe the comment from @kerams is valid && orthogonal => might be worth a separate suggestions for the optimizer to de-duplicate identical lambda-generated classes.

I honestly think we shouldn't be doing such analysis, since it can be quite complex with little benefits.

smoothdeveloper commented 10 months ago

The feature is going to be shipping but it is very difficult to get access to the RFC as it wasn't merged and the suggestion description doesn't mention it. Also no discussion thread was opened for the RFC itself.

I'm mostly concerned seeing the feature implementation is not restricted to properties only (which was Don main restraint for initial take on the feature) and will have a few rough edges on release in terms of tooling (which the F# users should be ok with, as things will be sorted out); but overall, we should make sure the suggestion discussion is closed in favor to a discussion related to the RFC, and that the RFC (even if not the last one) is visible in the repository itself, with the link to the discussion thread.

I'd prefer an almost empty RFC in the repository, with link to the discussion thread, and the suggestion being closed (with top post updated with links, as well as the closing comment), than the current situation.

(edit: and to be clear, I think users are going to love this feature, it is great feature that will have big impact on the codebases)