我有这个简单的 “箭”:意外的结果当上箭头一个Monoid的应用
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
的<+>
回报:
<foobar>}
{<foobar}
,如果我更换xform
有:
xform = ((prepend "<") >>> (append ">")) <+> ((prepend "{") >>> (append "}"))
我收到:
<foobar>
{foobar}
为什么我会得到这2个结果?即使在infixr
s(作为代码中的注释)也没有什么帮助。
[这可能会让你的解决方案](http://stackoverflow.com/questions/40331179/how-to-automatically-parenthesize-arbitrary-haskell-expressions)。 – Alec