Search code examples
haskellunicodechessghci

What problem does GHCi/Haskell have with the black pawn unicode character?


Of the following lines, Haskell seems to have problems only with the last one. The error when I load the file in GHCi is error: parse error on input ‘♟’.

xK = '♔'
xK = '♕'
xR = '♖'
xB = '♗'
xN = '♘'
xP = '♙'
xk = '♚'
xk = '♛'
xr = '♜'
xb = '♝'
xn = '♞'
xp = '♟︎'

Whatever the reason is, I find so strange that everything is just fine with the other 11 characters.

Might be important: I copied the characters straight from Wikipedia.


Solution

  • Your black pawn is secretly two codepoints. Compare:

    > "♟" -- entered myself
    "\9823"
    > "♟︎" -- copied and pasted from the question
    "\9823\65038"
    

    If you include only the first codepoint or change your binding from a Char to a String, it will work fine.