æ¥è¨
Arrow 㯠Monads ã®ä¸è¬åã ã¨èãããã¨ãã§ãããå ¨ã¦ã®Monadã¯Arrowã«å¤æãããã¨ãã§ããããArrowã¯Monadã«å¤æã§ããªãå ´åããããArrowåãå°å ¥ããç®çã¯Monadã使ãç®çã¨åãã§ãããã©ã¤ãã©ãªåãã«æ¨æºçãªåãç¨æãããã¨ã§ãããããããArrowåã¯Monadããåºç¯å²ã®æ¦å¿µããµãã¼ããããArrowåã§ã¯ãé¨åçã«éçãªè¨ç®ï¼åºåã®ä¸é¨ãå ¥åã«ä¾åããªãè¨ç®ï¼ããè¤æ°ã®å¼æ°ãåãè¨ç®ã表ããã¨ãã§ãããMonadã§ä¸æããããªãMonadã ãã使ãã°ããã®ã ããMonadã使ãããã ã使ããªã対象ã«å¯¾ãã¦ã¯ãArrowã使ãã¹ããããããªãã ã¾ãArrowã使ã£ãè¨æ³ã«é¦´ãããã¨ããå§ããããããã§ã¯ãç°¡åã®ãããæãã·ã³ãã«ãªé¢æ°ã表ãArrowã¨ãå°ããªãµã³ãã«ããã°ã©ã ãæ¸ããã¨ã«ããã ããã§ã¯ããã¹ãã¨ãã£ã¿ãç«ã¡ä¸ãã¦Haske
Arrowãå¦ã¶ãProgramming with Arrowsãèªãã§ããããArrowã®ã¯ãªããã¨ãããã³ãã³åç»ãã¿ãã®ããããããããã¤ã¡ã¼ã¸ã¯3çªç®ãåèã«ãªãã Programming with Arrows ãArrowã®ã¯ãªãã西å·ä» Haskell/Understanding arrows Arrowã使ã£ã¦å¥æ°åãä½ã£ã¦ã¿ãã 0ããå§ã¾ãæ°åã&&&ã§åå²ããã¦ä¸æ¹ã¯ãã®ã¾ã¾æ»ãã¦ãããä¸æ¹ã¯tailãããã¨ã§1ããå§ã¾ãæ°åã«ãã¦ãåæµããã足ãåãããã Prelude Control.Arrow> let odds = (tail) &&& id >>> (uncurry (zipWith (+))) Prelude Control.Arrow> take 10 $ odds [0,1..] [1,3,5,7,9,11,13,15,17,19]
æ¥æ¬èªã§Arrowã®èª¬æããã¾ãè¦ä»ãããªãã£ãã®ã§ãHaskell/Understanding arrows - Wikibooks, open books for an open worldãèªãã§ç解ããã¤ããã®ã¡ã¢ããªãªã¸ãã«ã®å³ãè¦ãªããã ã¨åãããããããã誤ãã»ééããªã©ãä¹ããææã b->cãªé¢æ°ãArrowãªãããããç®±ã«å ¥ããã¨ã (Arrow a) => a b c ãããªåã«ãªããåãã©ã¡ã¿ããå¼æ°ã®bã¨è¿å¤ã®cã®ãµãã¤ã Monadã¯ãå¤ãããããç®±ã«å ¥ãããã®ãããããç®±ã¯åºæ¬çã«(ãã³ãª)å¤ã Arrowã¯ãé¢æ°ãããããç®±ã«å ¥ãããã®ãããããç®±ã¯åºæ¬çã«(ãã³ãª)é¢æ°ã arr :: (b -> c) -> a b c Monadã§ã¯ãå¤ãããããç®±ã«å ¥ããé¢æ°returnãããã Arrowã§ã¯ãé¢æ°ãããããç®±ã«å ¥ããé¢æ°arrãããã (>>>)
Control.Arrow - mzsmsã®éè¨ãèªã㧠Arrow ã¨ãããã®ãç解ãããã¨ãã¦ããã ãã©ãapp é¢æ°ã§ã¡ãã£ã¨ã¤ã¾ãããã®ã§ã¡ã¢ãã¦ããã loop ã¯ããã¾ãã«ãåãããªãã£ãã®ã§å¾åãããªãã¨ãªãããªããããããåè·¯ã«ä¼¼ã¦ããæ°ã¯ããã åã§èãã¦ããå³ã«ãã¦ã¿ã æ©ãã§ãã³ã¼ãã¯å ã®ããã°ã®ãã®ã³ã¼ãã ghci> let g = id *** (*2) >>> app ghci> g ((+10), 2) app ã®åã¨ãé¢æ°ã¤ã³ã¹ã¿ã³ã¹ã«éå®ããã¨ãã®åã¨å¤ã¯ã app :: ArrowApply a => a (a b c, b) c app :: (a -> b, a) -> b app (f, a) = f a id *** (*2) ã®åã¯ã id *** (*2) :: Num a => (b, a) -> (b, a) >>> ã¯ã (>>>)
http://www.nicovideo.jp/watch/sm5103132 ã§ãHaskell(ã¨ãããGHC?)ã®Control.Arrowã«é¢å¿ãæã£ãã®ã§ããããããã£ã¦ã¿ãã loop ãã®1 ã¾ããç解ãé£ããloopããããªããªããã©ããArrowã使ãã¨ãã«ã¯ããããã¦ã³ã§èããªãã¨ãããåãããªããªããããªã®ã§ãããã¦ãã¨ã§åºãä¾ãããã ãã©ãç¹°ãè¿ããããä»äºã¯ä¸çªä¸ãloopã«ãªãã®ã§ãloopã«ä½ãå ¥ããã¹ããªã®ãããèãã¯ããããã¨ã«ãªãã ã¨ããããã(->)å(é¢æ°ãã®ãã®ã®å)ã®loopã®å®ç¾©ã¯æ¬¡ã®ã¨ãã: class Arrow a => ArrowLoop a where loop :: a (b,d) (c,d) -> a b c instance ArrowLoop (->) where loop f b = let (c,d) = f (b,d)
2012-08-21 John Wiegley ããã® âMonads in Picturesâ ã翻訳ãã¾ããã翻訳ã®å ¬éã¯æ¬äººãã許諾æ¸ã¿ã§ãã翻訳ã®ééãçãããã°é æ ®ãªããææãã ããã 2012å¹´8æ20æ¥ John Wiegley è 2012å¹´8æ21æ¥ e.e d3si9n 訳 ããã¯ã¢ããã®ãã¥ã¼ããªã¢ã«ã§ã¯ãªãããããã«ã¯æ°å¦ç¨èªãåºã¦ããªããæ¬ç¨¿ã¯ãæ¢ã«ã¢ãããä¸å¿ä½¿ãããããã«ã¯ç¿ã£ã人ã対象ã¨ãããè¦è¦åãããã¨ã§ãä½ã®ããã«ä½ããã£ã¦ããããæããã«ãªãã¯ãã ã é¢æ° ã¢ããã«å¯¾ããç´æãå¾ãä¸ã¤ã®æ¹æ³ã¨ãã¦é¢æ°ããã¢ããã¸ã®æ½è±¡åããã©ãã¨ãããã®ããããé¢æ°ãä½ããã£ã¦ããã®ããç°¡åãªçµµã§è¡¨ãã¦ã¿ãããHaskell ã®é¢æ°ã®å¼ã³åºãã®æ§æãä¸ã«ãåãæ¼ç®ãè¦è¦åãããã®ãä¸ã«ç½®ãã: é¢æ°ã¯ããå¤ a ãæå° (map) ãã¦å¥ã®å¤ b ãå¾ããä¸ã§ä½ãèµ·
æ¬å½ã¯ã Freeã¢ãããè¶ ããï¼ï¼operationalã¢ããã使ã£ã¦ã¿ãã http://fumieval.hatenablog.com/entry/2013/05/09/223604 ã«å½±é¿ããã¦ãOperationalã¢ããã®è©±ãã¾ã¨ãããã¨æã£ãã®ã§ãããã¡ãã£ã¨æéãªãããã ã£ãã®ã§ãä»æ¥ã¯ã¡ãã£ã¨CoYonedaã®è©±ããã¾ãããã ä¸è¨ããã°ã§ã¯ãCoYonedaã«ã¤ãã¦ããã ã®ãã¼ã¿åããFunctorãçã¿åºãããã¨ç´¹ä»ããã¦ãã¾ããããããã£ããã©ãããäºããã¡ãã£ã¨æ·±ã追ã£ã¦ã¿ã¾ãããã åãã« ä»åã¯ãä»»æã®åãFunctorã«ããäºãç®æ¨ãªã®ã§ãã¾ãç°¡åã«ä»¥ä¸ã®ãããªåãå®ç¾©ãã¦ããã¾ãã data Hoge a = Foo a | Bar a deriving Show ç±³ç°å çã¨Yoneda Yonedaã¨ããã®ã¯ç±³ç°ä¿¡å¤«ã¨ããæ¥æ¬ã®æ°å¦è ã®åã«å ãã ãç±³ç°ã®
åã ããæ°ã«ãªã£ã¦ããArrowãè¦ããã¹ãããã¡ãã¡è³æãæ¢ãã¦ã¿ããã®ã®ãããããæ¥æ¬èªã®è³æãå°ãªãã®ã§ãèªåã§è²ã ããã£ã¦è©¦ãã¦ã¿ãäºã«ãã¾ããã ä¸ã¤ã®æ¥æ¬èªè³æã¨ãã¦æ´»ç¨ã§ããããã«ãæé ã追ã£ã¦ä½åãã«å¥ãã¦ãªãã¹ã詳細ã«æ¸ãã¦ãããã¨æãã¾ãã èªåãåå¼·ããªããã«ãªãã¾ãã®ã§ã足ããªãé¨åããã¾ãããææããã ããã°å¹¸ãã§ãã ã¾ããArrowã®ãé¢æ°ããã¤ãæè¦ã§ç¹ãã§ããï¼äºãã§ãããããï¼>>> æ¼ç®åã®å®ç¾©ã¯æ¬¡ã®ããã«ãªã£ã¦ã¾ãã Prelude Control.Arrow> :i (>>>) (>>>) :: (Control.Category.Category cat) => cat a b -> cat b c -> cat a c -- Defined in Control.Category infixr 1 >>>ãã¡ããã¡ããã¦åããã¥ããã§ãããå¿ è¦
Programming with Arrowsãèªãã§ç解ããã¤ããã®ã¡ã¢ã誤ããªã©ä¹ããææã ï¼å¾©ç¿ï¼Arrowã£ã¦ãªã«ï¼ ã¨æã£ã¦ä»¥å調ã¹ãã¡ã¢ã"3åã§è§£ãHaskellã®Arrowã®åºæ¬ã¡ã¢ - ãããããã¾ãã"ãããã«ã¡ãã£ã¨è£è¶³ã¨ããã観ç¹ãå¤ãã¦ã¾ãæè¦ã®æ´çã Monadã«è²ããªç¨®é¡ãããããã«ãArrowãè²ããªç¨®é¡ãããã Monad: IOãMaybeã⦠Arrow: é¢æ°ãã®ã¾ãã¾(->)ãKleisli mã⦠ãã種é¡ã®Monadã«è²ããªåã®è²ããªå¤ãå ¥ããããããã«ããã種é¡ã®Arrowã«è²ããªåã®è²ããªé¢æ°ãå ¥ããããã Monad: Maybeã®ä¾â ãMaybe Intã ã«return 0ãreturn 777ãOKããMaybe Charã ã«return 'a'ãreturn ' 'ãOKã Arrow: (->)ã®ä¾â ãInt -> In
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}