替换Haskell中的"->"s with "→"s, "=>"s with "⇒"等等

Replacing "->"s with "→"s, "=>"s with "⇒"s and so on in Haskell

有很多有意思的地方 snippets to be found online. This post could be found under this (awesome) Stack Overflow question. The author写下如下:

discount ∷ Floating α ⇒ α → α → α → α
discount τ df x = x * (1 + df) ** (-τ)

那些花哨的箭头和点只是一种使在线页面看起来更好的方法,还是有一个实际的 Haskell 扩展(或其他,我不太了解术语)可以编译一些东西像那样?我应该注意到,代码中也使用了通常的 ->

我有一种强烈的感觉,这不是我第一次看到这样的事情。

来自 GHC 文档:

The language extension UnicodeSyntax enables Unicode characters to be used to stand for certain ASCII character sequences.

有一个名为 UnicodeSyntax 的 GHC 扩展允许一些 Unicode alternatives for certain syntax。但是,一般来说,Haskell 源代码是用 Unicode 编写的,因此非 ASCII 字符可以在纯 Haskell 源代码中用于标识符和运算符,即使没有任何扩展名。

在您问题中包含的代码片段中,作者同时使用了这两种工具。他们使用 UnicodeSyntax 来允许 Unicode 字符 代替内置的 ::=>-> 语法,但他们使用常规 Haskell Unicode 支持来编写 ατ 作为标识符。

以下程序在没有任何扩展名的情况下有效:

discount :: Floating α => α -> α -> α -> α
discount τ df x = x * (1 + df) ** (-τ)