-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attributes for local let
s
#848
Comments
C# already has this: dotnet/roslyn#38801 |
I think this is great to have, especially for literals, but I doubt it's going to be easy. Some things come to mind:
That's from the top of my head. There may be a lot of subtleties involved here. Alternatively, we could only allow a subset of attributes that are recognized by F# or by the CLR. |
Can we combine this with #984? I think both have merit, but need some ironing out |
This doesn't seem right for F#. The expression language has always been kept "simple" in the sense that it's largely just plain and simple functional programming with various additions to augment the power of FP. There's never been any real intention that it should be possible to reflect over the internals of compiled expressions. This also allows the compiler great leeway to perform optimziations. This philosophy seems stable and reasonable, and it needs some really big and important reason to allow the .NET-style attributions and other such reflective things to intrude into the expression language. Since I'm spring-cleaning I'll close this out for these reasons. |
Here is an example of why this is useful. I want to do the following so that the compiler will confirm that the inner function
If I put Yes, I could make |
@dsyme Attributes are not only for reflecting at runtime but also for various compile-time items like |
This works: let myState = 5
let inline processFive ([<InlineIfLambda>] simpleOp) =
simpleOp myState
let test =
processFive (fun c -> c + 1) +
processFive (fun c -> c - 1) The same code inside a function doesn't work: let myCodeContext() =
let myState = 5
// error FS0824: Attributes are not permitted on 'let' bindings in expressions
let inline processFive ([<InlineIfLambda>] simpleOp) =
simpleOp myState
let test =
processFive (fun c -> c + 1) +
processFive (fun c -> c - 1)
test ...so I have to cut the processFive out of the myCodeContext to somewhere else. Which is a bit annoying as then it leaks the "internal" myState out of myContext. |
Attributes for local
let
sI propose we allow attributes for local
let
s.The existing way of approaching this problem in F# is to put the
let
s that need attributes at the top level, polluting Intellisense.Pros and Cons
The advantages of making this adjustment to F# are
The disadvantages of making this adjustment to F# are none that I can think of.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: None
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: