In "Programming with Arrows", Hughes asserts
First of all, note that both first and left are easy to implement in terms of app (the details are left as an exercise).
From Control.Arrow, left
can be implemented as:
leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d)
leftApp f = arr ((\b -> (arr (\() -> b) >>> f >>> arr Left, ())) |||
(\d -> (arr (\() -> d) >>> arr Right, ()))) >>> app
How do I implement first
with just arr
, >>>
, and app
?
I think I got it, but I would be very interested if there is a simpler solution