[Haskell-cafe] Applicative banana brackets

martin monkleyon at googlemail.com
Wed Dec 9 05:09:21 UTC 2015


Hi,

while learning about all the type classes and their relationships I came
across something I found weird.
If I understand it correctly, banana brackets where originally developed
for Applicatives. The intent was to enable us to write something like

(| (\a b c -> a + b + c), [3], [1,2], [5,0,7] |)

and have it translated to

liftA3 (\a b c -> a + b + c) [3] [1,2] [5,0,7]

or alternatively, to allow us to write something like

(| (pure $ \a b c -> a + b + c), [3], [1,2], [5,0,7] |)

and have it translated directly to

pure (\a b c -> a + b + c) <*> [3] <*> [1,2] <*> [5,0,7]

A variant of banana brackets is implemented in ghc, but only for Arrows
as part of -XArrowSyntax. Arrows are just the intersection of
Applicative and Category, so this implementation seems to be a
specialization. What's worse, I don't think -XRebindableSyntax extends
to banana brackets.
But why? Is it hard to have the notation work with both? (After all, the
relationship between Arrows and Applicatives is not easily expressed in
Haskell.) Was the demand for (Applicative) bananas not big enough? Is it
just a relic?
And more to the point: I have not looked at the ghc code base at all
yet, but it's on my bucket list to hack on it one day. Right now, a
generalization of banana brackets seems like a simple enough low
pressure first project, but I fear that it might break code or that
there is some pitfall I'm not seeing.

Can anybody shed a bit of light on this?

Thanks and cheers,
Martin L.

P.S.: If the list receives this mail several times, I apologize. The
list management tool seems to be confused by gmail vs. googlemail.
That's what you get for using non-Haskell software. ;)


More information about the Haskell-Cafe mailing list