3

作为haskell 的绝对初学者,我一直在阅读有关haskell 的各种文章、pdf 和教程。大多数示例/示例代码都包含数学字符。即使是打字的常见任务

->

我必须输入: - & >

事实是我不知道如何在 emacs 中输入数学字符(我用于练习 haskell 编码)。我当前的键盘布局是“美国英语”。

是否有任何特定的键盘或键盘布局最适合输入数学符号(用于 haskell 编程)?

haskell 是否将所有数学符号作为函数?我目前的假设是,haskell 必须支持所有数学符号作为函数。

例如 +、-、/、* 等。

Unicode 数学符号 注意:这些符号出现在许多 haskell 论文中。

4

3 回答 3

10

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:

(setq haskell-font-lock-symbols t)

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 entering TeX. This will, for example, allow you to type \lambda and get a λ. To see the full list of symbols you can type, run M-x describe-input-method and then enter TeX.

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:

a +++ b = a * a + b * b

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.

于 2012-07-22T06:06:19.653 回答
6
于 2012-07-22T06:07:43.297 回答
1

我知道有一种用于编程的 Dvorak 风格,但似乎学习新的键盘布局比简单地为你必须敲击的新组合键建立肌肉记忆更难。

于 2012-07-22T02:04:54.173 回答