30

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?

2

1 Answer 1

41

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

3
  • 1
    Operators don't have to be infix, so this is legal: (πŸ™) [] = Nothing; (πŸ™) ((πŸ‘½):as) = Just (πŸ‘½); main = print $ (πŸ™) "a". Aug 13, 2015 at 2:03
  • Thanks. I wrongly assumed that (πŸ™) would force it to have a function type accepting two arguments, but that is only the case for operator sections, it seems. Bug #10772 filed about the it not working on the type level. Aug 13, 2015 at 7:32
  • Ah, very cool to see the update after the hint from user3237465 :) Aug 13, 2015 at 8:50

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.