Concealing Prefix Lifts

Posted on September 24, 2014

Concealing infix lift-like operations is easy. For example,

sin `liftA` [pi,tau]
sin ↥ [π,τ]

The two lines are equivalent (In real code it’ll be <$>, which is also concealed with ↥, because in essence it is a lift operation.)

Now, how to conceal the prefix version?

liftA sin [pi,tau]

It appears that we can exploit the nice properties of Haskell: the space operator has highest precedence, and since liftA f is always a function by itself (a lifted one), why not just write exactly that: a new function? Behold:

↥sin [π,τ]

Notice that there is no space between ↥ and sin, which means that ↥sin identifier is a function. (Well, technically not, since ↥ is not allowed in the first place, and surely is not a valid name identifier, but we can pretend. There is already a precedence of a similar dualism, i.e. the subtraction operator and the minus sign.) By prepending ↥ we just make a notation for a lifted function.

So, liftA sin produces a new function, which is ↥sin (read as “lifted sin function”). And now these are equivalent:

sin ↥ [π,τ] -- Take sin, lift it, and apply to a list
↥sin [π,τ]  -- Apply lifted sin to a list

Surprisingly, this concealing scheme can be easily implemented, I’ll publish it soon.