Skip to content
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

Richer literals: TimeSpan/DateTime/Char array/UTF8 #21

Closed
baronfel opened this issue Oct 20, 2016 · 3 comments
Closed

Richer literals: TimeSpan/DateTime/Char array/UTF8 #21

baronfel opened this issue Oct 20, 2016 · 3 comments
Labels

Comments

@baronfel
Copy link
Contributor

Richer literals: TimeSpan/DateTime/Char array/UTF8 [11109258]

Submitted by Tom Rathbone on 12/16/2015 12:00:00 AM
4 votes on UserVoice prior to migration

Combining several suggestions for richer literals

  • New literals for TimeSpan and DateTime. e.g.
    "01:02:03"T --> new TimeSpan(1,2,3)
    "2015-01-02 10:30:00"D -> new DateTime(2015,01,02,10,30,00)
  • Char[] e.g
    "abcd"C
  • UTF8 encoded strings "abc££def"U
    and indeed perhaps the whole mechanism should be extensible like QZRING literals

Original UserVoice Submission
Archived Uservoice Comments

@dsyme dsyme removed the open label Oct 29, 2016
@dsyme
Copy link
Collaborator

dsyme commented Oct 29, 2016

Type providers can be used to implement a very large range of literal forms. See for example: https://github.com/toburger/DateTypeProvider. Closing this since that extension mechanism is available.

@dsyme dsyme closed this as completed Oct 29, 2016
@dsyme dsyme added the declined label Nov 3, 2016
@cartermp
Copy link
Member

Posting here rather than creating a new issue.

See this lengthy issue detailing scenarios and designs around UTF-8 for .NET. Of particular interest here is that this is critical work for ML.NET. The bulk of this is in the runtime, but there are some language-level considerations, such as a possible representation for literals.

There is a C# proposal for UTF-8 string literals with some interesting discussion. The primary motivation:

When this functionality RTMs, it will not be possible to create or declare a UTF8String in C# without first either getting the raw bytes from some external source (such as returned by a File or Network stream) or by converting from a UTF16 based string.

From a principles standpoint I really do hate the idea of bifurcating strings, even though the space is inherently complicated once you dive into it. Given that .NET uses UTF-16 for System.String, I believe that UTF-8 needs to be a special consideration, much like how value types in user code are a special consideration: used judiciously and for the appropriate scenario.

The question in my mind is that if using a Type Provider can result in the same performance as if there were some language-level support for UTF-8 literals if you need to use them in, e.g., a hot loop. If it can, then the next question is if people consider that an acceptable dependency for working in scenarios outlines by the CoreFX Lab issue.

@jpierson
Copy link

I followed a link to this discussion from a separate C# proposal where I made some points that I think that would be valid here for F#. @dsyme I took a brief look at the DateTime literal type provider example that you pointed to but the syntax appears a bit outside of the proposed typical prefix/suffix approaches. I'm curious if by using Type providers if anything close to the syntax used with the ES6 feature for tagged template literals would be possible? My comment on the proposal can be found at the link below.

dotnet/csharplang#1775 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants