chansey
chansey

Reputation: 1429

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).

Upvotes: 3

Views: 565

Answers (2)

chansey
chansey

Reputation: 1429

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.

Upvotes: 0

Joachim Breitner
Joachim Breitner

Reputation: 25782

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.

Upvotes: 5

Related Questions