Last active
July 30, 2020 19:39
-
-
Save cartermp/742b6dfb3986f7c04d08607e52aba5de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Notes: | |
// 0. Immediately thrown off by `{` and `}` being colorized as the string literal | |
// 1. Bad expression diagnostic in the interpolation is correct | |
// 2. String literal in non-triple-quoted string diagnostic is good | |
// 3. Typing these out works well, editor doesn't freak out | |
// 4. symbol-based operations all work (symbol highlight, find refs, go to def) for symbols in interpolated stuff | |
// 5. Breakpoint can be set in the interp string on a single line | |
// 6. Using interp string with %d/%s/etc. specifiers adjusts the argument's type as expected (e.g., %d{whom} infers a valid type for 'whom') | |
// 7. Error recoviery for splitting the interpolated expression into a new line matches other rules for splitting things out into new lines | |
// 8. Quick fix to rename misspelled identifier in interpolation works | |
// 9. I can specify sprintf with an interpolated string -- why? I guess it's not harmful, just kinda redundant | |
// 10. 'fromCurriedBadString' has weird diagnostic - clearly I am missing something but trying to "curry" a value into the interpolated context, which is nonsense | |
// 11. Nested interpolations work, but completion of quotes and braces makes it kind of bad, especially when inside of triple quotes | |
let toPigLatinBadExpr (str: string) = | |
$"""{str.[1..] + str.[0] + "ay"}""" | |
let toPigLatinBadStringLiteral (str: string) = | |
$"{str.[1..] + str.[0] + "ay"}" | |
let toPigLatin (str: string) = | |
$"""{str.[1..] + string str.[0] + "ay"}""" | |
let don = "Don" | |
let symeroni = "Syme" | |
printfn $"First name: {don}\n Last name: {symeroni}" | |
// Define a function to construct a message to print | |
let from whom = | |
$"from %d{ | |
whom}" | |
let from whom = | |
$"from {whom}" | |
let from (whom: string) = | |
$"from {whom.Chars}" | |
// Can use currying with sprintf | |
let fromCurried = sprintf "from %s" | |
// Try to use "currying" (??) with interpolated string | |
// FS0010: Unexpected interpolated string (final part) in binding. | |
// What does this error message mean? (I know what it means from an implementation details standpoint, but not as a user) | |
let fromCurriedBadString = $"from {}" | |
// The error message persists across the whole string literal spanning the new line and beyond | |
let fromCurriedBadString2 = $"from {} | |
" | |
// FS0010: unexpected interpolated string (part) in binding | |
// But only between the two `{}`, not the whole string | |
// would have expected the whole string to give an error | |
let badString = $"{} is my name and {} is my game" | |
let rec machine = nameof machine | |
let nestedInterpString = $"""Hello {$"from the {machine}"}""" | |
type R = { Name: string; Age: int } | |
type DU = A of int * string | B | |
// Embedded record, needs a space either between the `{` and `}` or before the `{ for the interpolation | |
// as expected, need triple quotes to instantiate a string | |
let rString = $"""{ {Name = "hello"; Age = 12} }""" | |
// Not adding the space makes it all just a string literal | |
let rString' = $"""{{Name = "hello"; Age = 12}}""" | |
// Space after the first `{` works | |
let arString = $"""{ {| Name = "hello"; Age = 12 |}}""" | |
// Space before the `}` does NOT work | |
let arString2 = $"""{{| Name = "hello"; Age = 12 |} }""" | |
// Making it a struct means no problem :) | |
let sarString2 = $"""{struct{| Name = "hello"; Age = 12 |}}""" | |
// DU case works as expected | |
let duString = $"""{A(12, "hellow")}""" | |
let os = System.Text.StringBuilder() // line 1 | |
let _ = $"{0}" // line 2 | |
let _ = $"%A{0}" // line 3 | |
let _ = $"%7.1f{1.0}" // line 4 | |
let _ = $"%-8.1e{1.0}+567" // line 5 | |
let s = "value" // line 6 | |
let _ = $@"%-5s{s}" // line 7 | |
let _ = $@"%-A{-10}" // line 8 | |
let _ = @$" | |
%-O{-10}" // line 10 | |
let _ = $" | |
%-O{-10}" // line 13 | |
let _ = List.map (fun x -> sprintf $@"%A{x} | |
") // line 15 | |
let _ = $"\n%-8.1e{1.0}+567" // line 16 | |
let _ = $@"%O{1}\n%-5s{s}" // line 17 | |
let _ = $"%%" // line 18 | |
let s2 = $"abc %d{s.Length} and %d{s.Length}def" // line 19 | |
let s3 = $"abc %d{s.Length} | |
and %d{s.Length}def" // line 21 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment