Can unicode symbols be use as operator and where can I find list of charactors that are consider symbols? (That can use as operator, e.g. < + & * ...)

Some character are classified as symbols and can be use as operator. We see lots of them in the code. But I can’t find the list of symbols anywhere.

I wonder if Unicode symbols (assume it not hard to type in, using modern editor and familiarity with Latex) could be use without having to put ` around it.

For example

a ⊕ b = (++)

out a b c = (a ⊕ b, c)

I know it might not a good idea for using non-ASCII chars in general programming, just wonder if it can be done.

There is a language extension that allows you to use unicode symbols, you can read more in the wiki:

https://wiki.haskell.org/Unicode-symbols

The Haskell2010 report specifies in section 2.2 that “any Unicode symbol or punctuation” can be used.

The following works (without any language extension):

(©) = (+)
main = print (1 © 2)

I think more concretely, anything in the following categories is considered a symbol and can be used to define operators (I have done some testing):

  • Connector Punctuation
  • Dash Punctuation
  • Other Punctuation
  • Currency Symbol
  • Modifier Symbol
  • Math Symbol
  • Other Symbol

The UnicodeSyntax extension that @NobbZ mentioned only allows you to use some Unicode alternatives for already existing syntax. Listed on this page: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#unicode-syntax. That extension is not necessary to be able to define your own Unicode operators.

2 Likes