# [Haskell-cafe] Plain lambda inside banana brackets in the arrow notation

Tsuyoshi Ito tsuyoshi.ito.2006 at gmail.com
Thu Jul 5 23:55:07 CEST 2012

```Hello,

In a program, I have an arrow MyArr and a combinator called repeat of
the following type:

repeat :: Int -> (Int -> MyArr e a) -> MyArr e a

My problem is that the code becomes messy when I use this combinator
inside the arrow notation, and I am looking for a way to write the
code in a more readable way.

To explain the problem, first consider the following combinator
repeat', which is less general than repeat:

repeat' :: Int -> MyArr (e, Int) a -> MyArr e a
repeat' n f = repeat n g
where g i = arr (\e -> (e, i)) >>> f

Combinator repeat' is nice to use in the arrow notation, thanks to
banana brackets and the interpretation of lambda:

test1 :: MyArr [Double] String
test1 = proc xs -> do
let y = func1 xs
z <- job1 -< xs
(|(repeat' 100) (\i -> job2 -< xs !! i + y + z)|)

-- func1 :: [Double] -> Double
-- job1 :: MyArr [Double] Double
-- job2 :: MyArr Double String

However, in my program, I often have to use repeat instead of repeat' like:

test2 :: MyArr [Double] String
test2 = proc xs -> do
let y = func1 xs
z <- job1 -< xs
repeat 100 (\i -> proc (xs, y, z) -> job3 (i * 2) -< xs !! i +
y + z) -< (xs, y, z)

-- job3 :: Int -> MyArr Double String

Note that variable i is used as an argument to function job3 outside
MyArr, and this cannot be done with repeat'.

The code for test2 looks messy to me because I have to write “(xs, y,
z)”, that is, the list of variables used inside the subcomputation
explicitly (and twice).  It does not seem possible to use banana
brackets here because the type of the subcomputation does not meet the
requirements stated in