5 ms·
I think the way F# implemented it is pretty good: if you want to use a keyword or whitespace in a variable or function name, it has to be enclosed in double bac
by julesnp 3y ago
I think the way F# implemented it is pretty good: if you want to use a keyword or whitespace in a variable or function name, it has to be enclosed in double backticks.
e.g:
[<Property>]
let ``Reverse of reverse of a list is the original list`` (xs:list<int>) =
List.rev(List.rev xs) = xs
- lifthrasiir 3y agoI'm not sure if F#'s implementation is good enough. The specification [1] suggests that it doesn't do any additional normalization to the resulting identifier, so otherewise identical identifiers with a single space, a single tab and two spaces would be different. I would expect them to collapse into a single space character. [1] https://fsharp.org/specs/language-spec/4.1/FSharpSpec-4.1-latest.pdf#page=25 https://fsharp.org/specs/language-spec/4.1/FSharpSpec-4.1-la...
- chrismorgan 3y agoWhy would you expect that? I would explicitly expect not that. Unicode normalisation (typically to NFC) maybe, but nothing more.
- lifthrasiir 3y agoMostly because it's rare to see identifiers with whitespace allowed after all. So this has to fulfill some specific needs. The main use case here seems like self-describing properties that will be hardly referenced elsewhere. In principle this doesn't really need any new syntax, as you can put the description into the attribute (`[<Property>]` here) and the name itself can remain arbitrary or even be made anonymous. But we've got textual identifiers instead. So I guess that some code does refer to those textual identifiers, and if that's the case, being able to ignore invisible differences when comparing textual identifiers looks like a good idea as well.