When I try to use '\0'
as a character in F# it doesn't work. Here is what I see:
I have read elsewhere that Char.MinValue
will accomplish the same thing though.
Is there any reason why '\0'
is not supported?
When I try to use '\0'
as a character in F# it doesn't work. Here is what I see:
I have read elsewhere that Char.MinValue
will accomplish the same thing though.
Is there any reason why '\0'
is not supported?
The F# specification describes the grammar for char literals:
3.5 Strings and Characters
regexp escape-char= '\' ["\'ntbrafv]
regexp non-escape-chars= '\' [^"\'ntbrafv]
regexp simple-char-char= | (any char except '\n' '\t' '\r' '\b' '\a' '\f' '\v' ' \")
regexp unicodegraph-short = '\''u' hexdigit hexdigit hexdigit hexdigit
regexp unicodegraph-long= '\''U' hexdigit hexdigit hexdigit hexdigit hexdigit hexdigit hexdigit hexdigit
regexp trigraph = '\' digit-char digit-char digit-char
regexp char-char= | simple-char-char | escape-char | trigraph | unicodegraph-short
\0
matches none of these - if you want the null character you can use
let c = '\000'
or Char.MinValue
It is supported. Character literals in F# are either a unicode character or the 16-bit unicode number. It's just that the backslash means it's a short or long escape sequence.
let A = '\u0041' // Capital letter A
The ASCII version of this is '\nnn'. So
let A = '\065' // Capital letter A
And so \0
becomes \000
.
assert('\000' = Char.MinValue) // true
Please note that the unicode specifier is in hex, while the short sequence is in decimal.
DEC(65) = HEX(41)