Applicative style for infix operators?
-
12-12-2019 - |
Question
Is there a way to make applicative uses of <$>
and <*>
look nice when dealing with infix operators? I think that
((++) <$> a <*> ((++) <$> b <*> c ))
looks much more cluttered then
a ++ b ++ c
so I wonder if there is a nicer way.
Solution
(<++>) = liftA2 (++)
a <++> b <++> c
or
liftA2 (++) a $ liftA2 (++) b c
OTHER TIPS
See Thomas Davie's InfixApplicative package, which provides a general syntactic trick, rather than having to define a new operator for each lifting.
SHE lets you write
(|a ++ (|b ++ c|)|)
if that's any use. Of course, there's some overhead to introducing a preprocessing layer.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow