[Haskell-cafe] Applicative banana brackets
Tom Ellis
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Mon Dec 14 20:21:26 UTC 2015
On Mon, Dec 14, 2015 at 03:38:34PM +0100, martin wrote:
> On 2015-12-09 22:20, Tom Ellis wrote:
> >> 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
>
> > I don't think Arrow banana brackets are related to these Applicative (or
> > "Idiom") brackets.
>
> Let me try to convince you. ;)
OK :)
> Actually I have no idea if there is a historical relationship, but there
> is definitely a semantic one. Consider this:
1) - 3), all agreed.
> 4) An idiom bracket (| f x1 x2 ... xn |) translates very roughly to
> liftA (uncurryN f) (commaN x1 x2 ... xn)
> while a banana bracket (| f x1 x2 ... xn |) translates very roughly to
> liftA' (uncurryN f) (andAn x1 x2 ... xn)
But in an Applicative or Idiom bracket expression of the form (| f x1 ... xn
|), f is a pure function.
In the Applicative banana bracket, the expression that is in f's position is
*not* pure, instead it's an operator on arrows.
In the GHC users' guide we have
https://downloads.haskell.org/~ghc/7.2.2/docs/html/users_guide/arrow-notation.html
untilA :: ArrowChoice a => a e () -> a e Bool -> a e ()
...
... (|untilA (increment -< x+y) (within 0.5 -< x)|)
untilA is manifestly not a pure function. So, I don't think these brackets
are the same thing. I may have been wrong to say they are not related, but
I can't see that there's as close a correspondence as you are trying to make
out.
Tom
More information about the Haskell-Cafe
mailing list