-
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
Allow double dollar signs for interpolated strings as in C# 11 #1150
Comments
@alfonsogarciacaro this tries to solve the same problem: |
IMHO this feels like an elegant solution to the problem. |
Seems pretty reasonable |
This would also be useful for when working with JSON. |
As twitter has pointed out, the corresponding C# feature was clearly designed by someone deranged. Are you sure you want to follow what it does? |
@CyrusNajmabadi As you're probably aware:
So it'd be nice if you could elaborate why this feature is not desirable. If it's about the fact you can use more than two dollar signs in C#, I've also doubts about it, but using 2 dollar signs to avoid scaping braces would really be useful when handling JSON, CSS, etc. |
@CyrusNajmabadi Haha, sorry, I don't follow too closely the C# feature proposals so I didn't get the joke 😅 I just read the blog post announcing the C# 11 features. Actually, it's super nice that C# raw template strings are consistent with F# in using the triple quotes. Now the only thing we need is the double dollar in F# too for even better consistency 👍 |
I think this feature would be great for F# vNext as-suggested (and modulo some details in an RFC of course) |
Marking as approved in principle |
I'd like to take a stab at this. I assume an RFC is required? |
Note: just so it's not an accidental design decision. In C# it's not that we allow double-dollar-signs. We allow any number of them. So you can have 5 dollar signs. That means that any sequence of 4 or less is just text, and you need 5 to actually start the interpolation. The idea here (and a principle of hte c# design) is that there are no escapes. So if you need single curlies, you use double-dollar on the string. if you need doubled-curlies, you use triple-dollar on the string. etc. etc. you can always pick some number higher than the number of consecutive curlies in the content. Now, it's up to you if you want that complexity. But i just wanted to make sure the C# feature was understood, and people didn't accidentally think it was either one-or-two dollars, and nothing more. Thanks! |
I've just noticed that we likely shouldn't fully align with C# on how raw string (aka triple quote string) interpolation works, as in C#, a raw string starting with $"""{{""" (see in sharplab here) |
I have a work in progress PR with RFC for this suggestion here: fsharp/fslang-design#715 |
The RFC template has a Scaling section, it says:
I understand in this case it asks: Up to how many But I don't know what to base this on. @alfonsogarciacaro - perhaps you have some idea? |
For c# we placed no upper bound here. You can have as many $ as you want. |
In theory, it'd be nice to keep consistency with C# (although you mention above that would bring breaking changes in some cases), although in practice I cannot think of case where three or more BTW, great work with the RFC @abonie! Only thing is I would expect |
Thanks @alfonsogarciacaro! I also initially thought that dealing with N And the breaking change would be if we wanted to change how single- Which means, we should be able to support any count of Regarding the I will start a discussion thread for this RFC. |
That’s gonna be a good thing to have. Make sure to add a link to it here and from the rfc. On the scaling comment, I think it’s fine to leave it, or mention that it can limited by resources. Quite likely, the IDE language service will come to a grinding halt long before fsc itself would complain about it. Wrt tests, I guess we can write one or two tests with 10 or more dollars just to show the implemented feature is stable and applies the correct ranges for syntax colouring. In practice, this will rarely happen. On
Obviously, the 2nd choice, while more flexible, will be harder to implement, I think. |
Discussion started on fslang-design: fsharp/fslang-design#716 |
This is done by dotnet/fsharp#14640 |
F# interpolated strings, together with editor support, make for a great way to embed a language within F#, one example is Fable.Lit with the F# Template Highlighting VS Code extension that allows you to embed HTML/CSS directly into F#.
Unfortunately the experience becomes a bit impeded when using a language that includes frequent brackets and percent symbols, as users need to remember continuously to double them to escape them, and copy and pasting doesn't work. See attached image:
C# 11 has solved this by allowing users to use two (or more) dollar signs. In that case brackets work normally, and we need to use double brackets to open interpolation "holes". The example above would become just CSS:
Pros and Cons
The advantages of making this adjustment to F# are:
The disadvantages of making this adjustment to F# are:
%
would be an F# specificity. Definitely we should allow single%
when using double dollar, so probably format specifiers should be doubled then:margin: %%.2f{{value}}em 0;
Extra information
Estimated cost: Not sure, I guess it's mostly work in the parser?
Affidavit
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: