Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with this Haskell unicode variable name?

What's wrong this this code?

Prelude> let xᵀ = "abc"
<interactive>:10:6: lexical error at character '\7488'

According to my reading of the Haskell 2010 report, any uppercase or lowercase Unicode letter should be valid at the end of a variable name. Does the character (MODIFIER LETTER CAPITAL T) not qualify as an uppercase Unicode letter?

Is there a better character to represent the transpose of a vector? I'd like to stay concise since I'm evaluating a dense mathematical formula.

I'm running GHC 7.8.3.

like image 300
tba Avatar asked Jul 24 '14 19:07

tba


2 Answers

Uppercase Unicode letters are in the Unicode character category Letter, Uppercase [Lu].

Lowercase Unicode letters are in the Unicode character category Letter, Lowercase [Ll].

MODIFIER LETTER CAPITAL T is in the Unicode character category Letter, Modifier [Lm].

I tend to stick to ASCII, so I'd probably just use a name like xTrans or x', depending on the number of lines it is in scope.

like image 94
Boyd Stephen Smith Jr. Avatar answered Nov 15 '22 08:11

Boyd Stephen Smith Jr.


Characters not in the category ANY are not valid in Haskell programs and should result in a lexing error.

where

ANY         →   graphic | whitechar 

graphic     →   small | large | symbol | digit | special | " | '

small       →   ascSmall | uniSmall | _<br>
ascSmall    →   a | b | … | z<br>
uniSmall    →   any Unicode lowercase letter

...

uniDigit    →   any Unicode decimal digit 

...

Modifier letters like are not legal Haskell at all. (Unlike sub- or superscript numbers – which are in the Number, Other category so a₁ is treated much like a1.)

I like to use non-ASCII Unicode when it helps readability, but unless you've already assigned another meaning to the prime symbol using it here for transpose should be just fine.

like image 8
leftaroundabout Avatar answered Nov 15 '22 08:11

leftaroundabout