Difference between revisions of "Unicode-symbols"

From HaskellWiki
Jump to navigation Jump to search
(Removed hlint problems section (fixed in hlint-1.6.21))
(→‎Emacs: Replaced custom script with input method)
Line 67: Line 67:
 
Enter symbols directly: <tt>[http://www.gnu.org/software/emacs/manual/html_node/emacs/International-Chars.html C-x 8 RET]</tt>, then type either the character's name or its hexadecimal code point.
 
Enter symbols directly: <tt>[http://www.gnu.org/software/emacs/manual/html_node/emacs/International-Chars.html C-x 8 RET]</tt>, then type either the character's name or its hexadecimal code point.
   
'''Custom script'''
+
'''Custom input method'''
   
darcs get http://code.haskell.org/~roelvandijk/code/emacs-unicode-symbols
+
darcs get http://code.haskell.org/~roelvandijk/code/haskell-unicode-input-method
   
In your .emacs file:
+
To automically load in haskell-mode put the following code in your .emacs file:
(load "~/elisp/emacs-unicode-symbols/haskell-symbols")
+
(load "~/elisp/haskell-unicode-input-method/haskell-unicode-input-method")
  +
(add-hook 'haskell-mode-hook
(defun haskell-unicode () (local-set-key (kbd "C-M-u") 'replace-haskell-unicode))
 
(add-hook 'haskell-mode-hook 'haskell-unicode)
+
(lambda () (set-input-method "haskell-unicode")))
  +
Edit where appropriate depending on where you placed the elisp file.
   
  +
To manually enable use '''<tt>M-x set-input-method</tt>''' or '''<tt>C-x RET C-\</tt>''' with '''<tt>haskell-unicode</tt>'''. Note that the elisp file must be evaluated for this to work.
With above hook installed navigate the point to right after a normal symbol like '''->''' and press '''<tt>C-M-u</tt>''' to transform it into a beautiful '''&rarr;'''.
 
   
  +
Now you can simply type '''->''' and it is immediately replaced with '''&rarr;'''. Use '''<tt>C-\</tt>''' to toggle the input method. To see a table of all key sequences use '''<tt>M-x describe-input-method haskell-unicode</tt>'''.
''Caveat'': The author is an absolute Lisp newbie. Patches to above script are more than welcome.
 
  +
  +
Note that the sequence <= is ambiguous and can mean either '''&lArr;''' or '''&le;'''. Typing it presents you with a choice. Type 1 or 2 to select an option or keep typing to use the default option.
   
 
'''Abbrev mode'''
 
'''Abbrev mode'''

Revision as of 10:30, 19 September 2010


Overview

An overview of the packages that provide Unicode symbols.

Naming: A package X-unicode-symbols defines new symbols for functions and operators from the package X.

All symbols are documented with their actual definition and information regarding their Unicode code point. They should be completely interchangeable with their definitions.

Alternatives for existing operators have the same fixity. New operators will have a suitable fixity defined.

UnicodeSyntax

GHC offers the UnicodeSyntax language extension. If you decide to use Unicode in your Haskell source then this extension can greatly improve how it looks.

base-unicode-symbols

Extra symbols for the base package.

 API docs: http://hackage.haskell.org/package/base-unicode-symbols
 darcs get http://code.haskell.org/~roelvandijk/code/base-unicode-symbols

Problematic symbols

Original Symbol Code point Name
not ¬ U+AC NOT SIGN

The problem with this symbol is that you would like to use it as a unary prefix operator:

 ¬(¬x) ≡ x

Unfortunately this is not valid Haskell. The following is:

 (¬)((¬)x) ≡ x

But you can hardly call that an improvement over the simple:

 not (not x) ≡ x

====New symbol ideas==== (please add your own)

containers-unicode-symbols

Extra symbols for the containers package.

 API docs: http://hackage.haskell.org/package/containers-unicode-symbols
 darcs get http://code.haskell.org/~roelvandijk/code/containers-unicode-symbols

====New symbol ideas==== (please add your own)

Input methods

These symbols are all very nice but how do you type them?

(please add info for other editors)

Emacs

Direct

Enter symbols directly: C-x 8 RET, then type either the character's name or its hexadecimal code point.

Custom input method

 darcs get http://code.haskell.org/~roelvandijk/code/haskell-unicode-input-method

To automically load in haskell-mode put the following code in your .emacs file:

 (load "~/elisp/haskell-unicode-input-method/haskell-unicode-input-method")
 (add-hook 'haskell-mode-hook 
   (lambda () (set-input-method "haskell-unicode")))

Edit where appropriate depending on where you placed the elisp file.

To manually enable use M-x set-input-method or C-x RET C-\ with haskell-unicode. Note that the elisp file must be evaluated for this to work.

Now you can simply type -> and it is immediately replaced with . Use C-\ to toggle the input method. To see a table of all key sequences use M-x describe-input-method haskell-unicode.

Note that the sequence <= is ambiguous and can mean either or . Typing it presents you with a choice. Type 1 or 2 to select an option or keep typing to use the default option.

Abbrev mode

The Abbrev mode is not suitable since it only deals with words, not operators.

Agda

Use Agda's input method.