I have this simple "arrows":
main = do
let
-- arr :: (Arrow a) => (b -> c) -> a b c
-- (>>>) :: Category cat => cat a b -> cat b c -> cat a c
-- (<+>) :: ArrowPlus a => a b c -> a b c -> a b c
-- infixr 5 <+>
-- infixr 1 >>>
-- runKleisli :: Kleisli m a b -> a -> m b
prepend x = arr (x ++)
append x = arr (++ x)
xform = (prepend "<") >>> (append ">") <+> (prepend "{") >>> (append "}")
xs = ["foobar"] >>= (runKleisli xform)
mapM_ putStrLn xs
The <+>
returns:
<foobar>}
{<foobar}
and if I replace the xform
with:
xform = ((prepend "<") >>> (append ">")) <+> ((prepend "{") >>> (append "}"))
I get:
<foobar>
{foobar}
Why I get these 2 results? Even looking at infixr
s (as comments in the code) doesn't really help.
Lets write that a bit more to the point:
Now
xform
, becauseinfixr 5 <+>
binds more tightly thaninfixl 1 >>>
, is parsed aswhich as a diagram reads
whereas
xform'
corresponds simply toThat should explain it.