As an absolute beginner in haskell, I am continuously reading various articles, pdfs , tutorials on haskell. Most of the examples / sample codes include Math Characters. Even for a common task of typing
->
I have to type: – & >
The fact is I don’t know how to type Math Characters in emacs (I am using for practising haskell coding). My current Keyboard Layout is ‘English US’.
Is there any specific keyboard or keyboard layout which is most suitable for entering the math symbols (for haskell programming)?
Does haskell has all Math Symbols as functions? My current assumption is that haskell must be supporting all Math Symbols as functions.
e.g. +, – ,/, * etc.
Unicode Math Symbols
Note: These notations are seen in many haskell papers.
You do not have to use the fancy unicode symbols you see in papers–in place of → you can write
->and so on for each special character. Given this, a normal US Qwerty layout is perfectly find for Haskell.However, if you find the → style easier to read (but obviously not easier to type), you can have Emacs display code with those symbols instead. This is entirely cosmetic, like syntax highlighting: even though you see a →, the source code still has a
->and that’s still what you type. You can enable this as so:This symbol mode might make some of your indentation look a little odd. However, I’ve been using it for a while and have had no problems at all. I certainly like looking at my code more when it uses pretty symbols in place of ASCII surrogates.
So you still type -> but it just looks prettier.
However, sometimes you do want fancy symbols like Greek letters. For example, if you’re implementing an algorithm from a paper, it might make sense to keep the variable names the same. For this, you can use Emacs’s TeX input mode via
C-\and enteringTeX. This will, for example, allow you to type\lambdaand get aλ. To see the full list of symbols you can type, runM-x describe-input-methodand then enterTeX.Finally: Haskell does support all the “math symbols” like + and – as operators. In fact, any identifier made up of these characters is automatically infix. So you can actually define your own operators. You could write something like:
and then you would be able to use the
+++function in an infix position, like any other operator. I believe that Haskell determines which characters are “operator characters” by looking at its Unicode category, meaning you can define (and I actually have defined) operators like×.In summary: you do not need any special symbols for Haskell code–it can all be ASCII. You can make Emacs render ASCII Haskell code with those symbols if you find them easy to read, and you can actually type them using the TeX input mode.