Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# Units of Measures with Unicode characters symbols, what is the exact restriction?

I use F# 4.0 / VS-2015

This works fine

[<Measure>] type percent
let x1 = 100<percent>

but this would be nicer

[<Measure>] type %  // Percent
let x2 = 100<%>

[<Measure>] type €  // Euro
let cost = 99.99<€>

Because the % is used in F#, any other Unicode Symbols can be used. Some of them are allowed and some not.

The question is, what are the restrictions?

With knowing this, for other applications, the search for Unicode symbols can maybe pre-filtered.

allowed

[<Measure>] type ᚖ   // U+1696
[<Measure>] type ᕎ  // U+154E
[<Measure>] type ඖ  // U+0D96
let x3 =   0<ඖ>
let x4 =  50<ᕎ>

not allowed

[<Measure>] type (%)    // error FS0010: Unexpected prefix operator in type name. Expected infix operator, quote symbol or other token.    
[<Measure>] type  %     // error FS0010: Unexpected symbol '{0} in type name
[<Measure>] type (﹪)    // error FS0010: Unexpected character '﹪' in type name. Expected infix operator, quote symbol or other token.     
[<Measure>] type ﹪      // error FS0010: Unexpected character '﹪' in type name
[<Measure>] type ﹪  // ﹪ U+FE6A       
[<Measure>] type ٪   // ٪ U+066A     
[<Measure>] type %   // % U+0025          
[<Measure>] type %  // % U+FF05         
[<Measure>] type ‰   // ‰ U+2030 promille
[<Measure>] type €   // € U+20AC
[<Measure>] type ≷   // ≷ U+2277
[<Measure>] type _%
like image 465
Functional_S Avatar asked Sep 26 '22 07:09

Functional_S


1 Answers

So if you dive through the spec, A measure type must start with

ident-start-char:letter-char or "_"

where letter-char is from one of the following unicode classes:

'\Lu' '\Ll' '\Lt' '\Lm' '\Lo' '\Nl'

I haven't actually checked whether your characters are in those classes, but I think the general idea is that things that look like letters should be allowed.

like image 88
John Palmer Avatar answered Oct 13 '22 12:10

John Palmer