I've recently come across a bot on Twitter named EmojiHaskell, that claims to tweet 'interpretable Haskell code with emoji variable names'. A particular Tweet caught my attention, as it looked like malformed syntax to me, so I decided to take a closer look. So far I've produced the following code:
module Main where
š :: [š³] -> Maybe š³
š [] = Nothing
š (š½:as) = Just š½
main = print $ š "ā„"
Since I've used Ī»
on occasion in my Haskell code, I expected this code to work, but it appears that GHC doesn't like the emoji at all.
With $ runhaskell Main.hs
I get:
Main.hs:4:1: parse error on input āšā
I've already had a look at the UnicodeSyntax extension, and tried to only use some or single emoji instead of all of them to see if a certain one provokes the problem.
Now my question is this: Is there currently a Haskell compiler that would accept the code? Can I get GHC to work with this code somehow?
That code is not valid haskell. The reason is that š (like, probably, all Emojis) is a symbol character:
Prelude> import Data.Char
Prelude Data.Char> generalCategory 'š'
OtherSymbol
But you can still use them like any other symbol, namely as an operator:
Prelude Data.Char> let (š) = (+)
Prelude Data.Char> 32 š 42
74
Furthermore, as user3237465 pointed out, if you use the prefix syntax for operators, i.e. put it in parentheses, you can even use it like any other symbol:
(š) :: [a] -> Maybe a
(š) [] = Nothing
(š) ((š½):as) = Just (š½)
main = print $ (š) "ā„"
This is almost the example in the original post. Unfortunately, this trick does not work for the type variable. The the documentation is worded a bit unfortunately, but in fact symbols are never type variables and always type constructors
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