If you've been bored enough to peek at any of my Haskell or Purescript code, you might have noticed a Helpers.hs
file in multiple repos. These files contain convenience functions that vary from project to project, but a few symbols have consistently appeared in each one.
Haskell and Purescript are both symbol heavy already, and capable of parsing UTF-8, so I thought it made sense to make use of unicode symbols for common operators in my personal projects. I had just a few criteria:
≫
for *>
makes a lot of sense, but ≫
is really small in the default MacOS font for whatever reason. Maybe it'd look better under different settings, but I don't care enough to find out.There are some obvious wins right off the bat, and they feature heavily in my articles already. A function
f :: Eq a => a -> a -> Bool
can be rewritten in unicode as
f ∷ Eq a ⇒ a → a → Bool
The digraphs for ∷
, ⇒
, and →
are simply their ASCII equivalents.
In Purescript, forall
can be rewritten as ∀
, which is just the digraph FA
.
I stretched things a bit further with some other symbols though.
-- Digraph 0.
f ⊙ g = f <$> g
infixl 4 ⊙
-- Digraph 0M
f ● g = f <*> g
infixl 4 ●
-- Digraph Tl
f ◁ g = fmap f . g
infixr 9 ◁
-- Digraph PL
f ◀ g = f <=< g
infixr 1 ◀
-- Digraph Dw
α ◇ ω = α <> ω
infixr 5 ◇
The first two entries are symbolic synonyms for <$>
and <*>
. I tried to keep things consistent by making the applicative darker in order to indicate its increased "power" over map. I could not find a suitable symbol for >>=
, which is fine, because I already like the way that one looks.
This same "darker = more power" metaphor holds for ◁
and ◀
, which are point free versions of fmap
and >>=
respectively. Interestingly enough, I don't think ◁
has an ASCII equivalent in Haskell, despite me using it all the time. I think these communicate flow quite well and can make tacit code surprisingly readable.
The only other symbol I introduced was ◇
to append stuff. The alternative operator <|>
had no alternative. Thought there might be some kinda glyph in electrical engineering that covered that, but nothing in the standard Vim digraphs at least.
Guess I might also replace /=
with ≠
if I had to, which is just the digraph !=
. Probably wouldn't touch ==
though.
I took inspiration from Vasiliy Yorkin's Purescript symbols here, but rejected most of his choices for font reasons.
These are nice-ass symbols. I've been using them for a year+ now, and they still make sense to me when I go back to refactor old code. Give them a go.