There are a lot of interesting haskell snippets to be found online. This post could be found under this (awesome) Stack Overflow question. The author writes the following:
discount ∷ Floating α ⇒ α → α → α → α
discount τ df x = x * (1 + df) ** (-τ)
Are those fancy arrows and dots just a way to make the online page look nicer, or is there an actual Haskell extension (or whatever, I don't quite know the terminology) which would compile something like that? I should note that the usual ->
is used in the code just as well.
I have a strong feeling it's not the first time I see things like that.
There's a GHC extension called UnicodeSyntax
that allows some Unicode alternatives for certain syntax. However, in general, Haskell source code is written in Unicode, so non-ASCII characters can be used in plain Haskell source code for identifiers and operators, even without any extension.
In the code snippet you include in your question, the author is using both facilities. They are using UnicodeSyntax
to allow the Unicode characters ∷
, ⇒
and →
in place of the built-in ::
, =>
and ->
syntax, but they are using the regular Haskell Unicode support to write α
and τ
for identifiers.
The following program is valid without any extension:
discount :: Floating α => α -> α -> α -> α
discount τ df x = x * (1 + df) ** (-τ)
From the GHC docs:
The language extension UnicodeSyntax enables Unicode characters to be used to stand for certain ASCII character sequences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With