-
Notifications
You must be signed in to change notification settings - Fork 831
[WIP] RFC FS-1001 - String Interpolation #921
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
Conversation
c58764b to
15f39cd
Compare
|
Would it be preferable to use interpolation notation similar to other languages? Common things are |
|
A swift sample: |
|
I'm split on the |
|
Yes sure. Frankly it's something that's easy to change anyway. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these test should be in Compiler unit tests.
FSharp.Core shouldn't know about string interpolation.
ec413d0 to
384fadd
Compare
|
just noticed the following last line crashes at runtime with seems we can't format ints. |
|
OK "fixed" that NRE exception by making it the same error class like |
|
@dsyme, @v2m @7sharp9: I assume the issue is at https://github.com/Microsoft/visualfsharp/pull/921/files#diff-5b9ab9dd9d7133aaf23add1048742031R6376 correct? what can we do? |
|
Erm ... dunno, I not looked at the WIP on this lately :-) |
|
I think a spec for this would be preferable to a prototype. It was possible to discus the general approach that was taken for C# before a line of code was written. At the very least decide if we want interpolation in string.Format, printf or both. Should we mimic the C# syntax and format specs, or use the F# syntax ... or both, give some examples of what strings using interpolation look like to illustrate arguments for and against each spec requirement. Let's discuss the language needs for the feature before we pile in and write a ton of code. This seems like a pretty scary feature to "just evolve and debate" Kevin |
|
As already written above: language design is at https://github.com/fsharp/FSharpLangDesign/blob/master/FSharp-4.1-Proposals/StringInterpolation.md I just rebase an existing explorative implementation on the latest master and added couple of tests to see how far it went. |
|
I don't think Steffen expects this to go straight through into master - I don't see a problem with anyone prototyping a sample string interpolation if for no other reason than to get us all thinking about how this could work in the real world (if at all). |
|
@forki Nice work bringing this feature back to life. I think this has been discussed thoroughly in the links at the top of the page, I was really disappointed that it was dropped in F#4 when it was so close to completion. |
|
I think it should be string interpolation (as it's in C#), not |
|
@vasily-kirichenko yes that would make sense as well and unify sprintf and String.Format - since it would be already interpolated at that time. |
|
I assume most people here know the Scala solution to this, but just in case I want to point that one out, as I think it is quite elegant. The key point is that it has a concise syntax and is extensible. with formatting: The above examples are taken from: And plain SQL queries: (http://slick.typesafe.com/doc/3.1.1/sql.html#string-interpolation) and even things like ReactJS-like JSX/TSX xml-based syntax: (example from http://docs.scala-lang.org/sips/completed/string-interpolation.html) |
|
@jarlestabell scala syntax and extensibility it's really interesting, @jarlestabell can you post your comment in the string interpolation discussion in f# lang design repo? fsharp/fslang-design#6 so this pr can remain focused on implementation. |
|
@enricosada Done, thanks! :) |
|
Another option for adding formatting: It would be nice to keep the formatting options. Whether this way or the ways that were suggested above. Can't wait to get this feature. |
|
@KevinRansom Let's keep open any WIP PRs that correspond to an approved F# RFC. Inactivity is OK for RFCs - they can take months or years to get through the system. |
|
I'm not sure if @dsyme has decided which syntax we will use? Is this
|
|
I think we should just finally pick one of the syntaxes and release it. Finally. |
|
@vasily-kirichenko @forki @AviAvni The RFC is here: https://github.com/fsharp/FSharpLangDesign/blob/master/RFCs/FS-1001-StringInterpolation.md The basic proposed syntax is covered there. However the RFC really needs considerable work. I'd particularly recommend that someone go over all the comments in this thread, and in the RFC discussion thread, and the original codeplex thread, and capture all the remaining issues and list them at the end of the RFC. We can then resolve them one by one. |
|
The implementation works with string expressions only because of forki@6542316#diff-5b9ab9dd9d7133aaf23add1048742031R6583 where coercion from mkCoerceIfNeeded cenv.g cenv.g.obj_ty cenv.g.string_ty sWhat we need here is real type of each expression |
|
Closing |
|
@KevinRansom again - why has this been closed? |
|
@isaacabraham Same response as here #908 (comment). The issue is tracked by an RFC which is definitely still active, and we can resubmit this work (or a variation of it) for F# 4.2 |
|
I'm going to rebase this on master again and just implement for test purposes the C# syntax. There's nothing particular wrong with extending this later again. |
|
@forki do you want to give me access to your PR or should I open another separate PR? |
|
it's closed. go ahead and submit your own |
|
Alright then, thank Sir! |
I "rebased" the original prototype by @v2m on the current master and made it compile.