ãã£ã¼ã«ãã©ãã«
runContã¯é¢æ°ã§ã¯ãªãã¦ãã£ã¼ã«ãã©ãã«ãé¸æé¢æ°ã¨ãã¦ä½¿ã£ããã®ã ã£ãã
Continuation ã¢ãã
http://www.sampou.org/haskell/a-a-monads/html/contmonad.html
newtype Cont r a = Cont { runCont :: ((a -> r) -> r) } -- r ã¯è¨ç®å ¨ä½ã®æçµã®å
newtypeã®å·¦è¾ºã® Cont r a ã¯ã¾ã ä¸æã ãã©ãå³è¾ºã®æå³ã¯ãContã¨ããã³ã³ã¹ãã©ã¯ã¿ã§ä½ããããã¼ã¿ã¯ãä¸èº«ã«((a -> r) -> r)ã¨ããé¢æ°ãæã£ã¦ããããã®ä¸èº«ã§ããé¢æ°ã«ã¯cunContã¨ããåå(ãã£ã¼ã«ãã©ãã«)ãã¤ãã¦ãããã¨ãããã¨ã
JavaScriptã§ããã¨ãc = new Cont( function(){} ) ã§ä½ã£ãcãã{ runCont : function(){} } ã¨ãªã£ã¦ãããã¿ãããªã¤ã¡ã¼ã¸ã
A Gentle Introduction to Haskell: Types, Again
data 宣è¨ã«ãããæ§ç¯åã¯ããã£ã¼ã«ãå(æ³¢æ¬å¼§ã§ããã ãã¦)ä»ã§å®£è¨ããããã¨ãããã¾ãããã£ã¼ã«ãåã¯æ§ç¯åã®æ§æè¦ç´ ãä½ç½® ã«ãã£ã¦ã§ã¯ãªããååã§åå®ãã¾ãã以ä¸ã¯ããã²ã¨ã¤ã® Point ã® å®ç¾©ã§ããdata Point = Pt {pointx, pointy :: Float}ãã®ãã¼ã¿åã¯ãã®åã§å®ç¾©ãã Point ã¨åä¸ã®ãã®ã§ããæ§ç¯å Pt ã¯ä¸¡æ¹ã§ããªãã§ãããããããã®å®£è¨ã§ã¯ãµãã¤ã®ãã£ã¼ã«ãåã pointx 㨠pointy ã¨ãå®ç¾©ããã¦ãã¾ãããããã®ãã£ã¼ ã«ãåã¯æ§é ã®ä¸ããæ§æè¦ç´ ãåãåºãããã®é¸æé¢æ° ( selector function ) ã¨ãã¦ã使ããã¨ãã§ãã¾ãã
ã¤ãã¯ããããã®é¸æé¢æ°ãã¤ãã£ãé¢æ°å®ç¾©ã§ããabsPoint :: Point -> Float absPoint p = sqrt (pointx p * pointx p + pointy p * pointy p)http://www.sampou.org/haskell/tutorial-j/moretypes.html
ãªã®ã§ãé¸æé¢æ°ã¨ãã¦ä½¿ãé¨åã¯ãJavaScriptã§ããã¨ãp.pointx ã¿ãããªã¤ã¡ã¼ã¸ã
ãã£ã¦ãrunCont c k ã¯runContã2å¼æ°ãåãåãé¢æ°ã¨ããããã¯ãcããrunContã§åãåºããé¢æ°ã«å¼æ°kãé©ç¨ãã¦ããã¨è¦ãã¹ãã
runCont c k ã¯ãJavaScriptã§ããã¨ãrunCont(c)(k)ã§ã¯ãªãã¦ãc.runCont(k)ã¨ããæãã