箭头教程预告片

时间:2017-05-09 15:43:32

标签: haskell arrows

我无法理解teaser in the HaskellWiki arrows tutorial

中的代码
main :: IO ()
main = do
    let
        prepend x = arr (x ++)
        append  x = arr (++ x)
        withId  t = returnA <+> t
        xform = (withId $ prepend "<") >>>
                (withId $ append ">") >>>
                (withId $ ((prepend "!") >>> (append "!")))
        xs = ["test", "foobar"] >>= (runKleisli xform)
    mapM_ putStrLn xs

,其中

   (withId f) >>> (withId g) =
   (returnA <+> f) >>> (returnA <+> g) =
   ((arr id) <+> f) >>> ((arr id) <+> g)

   ((id . id) x) ++ ((id . f) x) ++ ((id . g) x) ++ ((g . f) x) =
   x ++ (f x) ++ (g x) ++ ((g . f) x)

在最后两行中,我无法弄清楚组成(。)的分配属性究竟来自何处

0 个答案:

没有答案