简体   繁体   中英

Haskell doesn't support unicode symbol constructor (e.g.: ◁)?

For example:

{-# LANGUAGE UnicodeSyntax #-}

data Symbolic n
  = Constant n
  | Variable String
  | Symbolic n :+ Symbolic n
  | Symbolic n :* Symbolic n
  | Symbolic n :◁ Symbolic n
  deriving (Show)

This code loaded successfully in GHCi.

Then I input:

Constant 2 :* Variable "a"

That's OK.

But when I input:

Constant 2 :◁ Variable "a"

*** Exception: : hPutChar: invalid argument (invalid character)

Does this mean that Haskell does not support Unicode symbol constructor?

How to make it support Unicode symbol constructor?

Environment: GHCi 8.6.3 (WinGHCi) Windows 7

Thanks.

New observation:

It works when ◁ appeared in source file, but you can not input ◁ in REPL (I use WinGHCi).

The problem is not with your code, or constructors, but simply that your environment is not set up so that Haskell can print unicode characters. Try

Prelude> putStrLn "\9731"

and you should see the same problem.

I am not an expert on Unicode and Windows, but presumably you can fix this by setting a LANG=C.utf8 environment variable, or similar.

Following @Cubic, this issue can be workaround by running chcp 65001 before GHCi.

I use stack in windows 7 command line:

X:\you-path> chcp 65001

X:\you-path> stack ghci

*Main> Constant 2 :◁ Variable "a"

Constant 2 :◁�� Variable "a"

It works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM