Skip to content

Conversation

@baronfel
Copy link
Contributor

@baronfel baronfel commented Nov 24, 2020

lambda

when passing a C# lambda (wrapped in parens), the compiler sees it as (roughly):

SynExpr.Paren(
  SynExpr.App(
    SynExpr.App (
      Ident "op_EqualsGreater",
      <expr for lambda args>
    ),
    <expr for lambda body>
)

so we can extract that pattern out and rewrite it.

This handles the following cases:

  • someFunc (thing => otherthing)
  • let thing = args => body

@baronfel baronfel force-pushed the replace-csharp-lambda-with-fsharp branch from 70be538 to 5b7bf93 Compare November 24, 2020 22:53
@baronfel
Copy link
Contributor Author

reporting of this error is much better now. I'd love to hear about more scenarios where we can detect this.


member scope.TryRangeOfParenEnclosingOpEqualsGreaterUsage opGreaterEqualPos =
let (|InfixAppOfOpEqualsGreater|_|) =
function | SynExpr.App(ExprAtomicFlag.NonAtomic, false, SynExpr.App(ExprAtomicFlag.NonAtomic, true, Ident "op_EqualsGreater", actualParamListExpr, _), actualLambdaBodyExpr, _) -> Some (actualParamListExpr, actualLambdaBodyExpr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I freaking love active patterns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so fun fact: this is the shape of this erroneous usage, so any more cases we want to cover should just be a matter of plugging this into the appropriate expr match.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without active patterns, matching the F# AST would be so much harder!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants