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

Ross Paterson ross at soi.city.ac.uk
Sun Jul 15 21:02:43 CEST 2012


On Sun, Jul 15, 2012 at 06:51:07PM +0100, Tsuyoshi Ito wrote:
> Thank you for the response.  This sounds exciting, but sadly, I must
> admit that it is a little (?) above my head, and I cannot relate this
> extension to my original question….

Sorry about that -- I got a bit side-tracked.  The combinator you wanted
to use was

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

That won't be possible, but with this extension you could use

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

The definition of StaticArrow (in the arrows package) is a wrapper

    newtype StaticArrow f a b c = StaticArrow (f (a b c))

so StaticArrow ((->) Int) MyArr e a ~= Int -> MyArr e a.
Now you could write

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

which isn't quite what you wanted, because i wouldn't be in the environment,
but we could put it there as you did in your original post, or something
like

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

I did say it would be clunky, but at least there's no dumping the tuple
and picking it up again.



More information about the Haskell-Cafe mailing list