ï¼ï¼åãã«
ããã¾ã§ããã¾ãã¾ãªè¨èªã§ããã°ã©ãã³ã°ãã¦ããããä¸çªæºè¶³ãã¦ããã®ã¯Haskellã§ããããªãã¨ããåãã«ä¸è¨ã§çãããªãã°ããã°ãå
¥ãã«ããããããã¯ãããã°ã©ã ãä¿¡ç¨ã§ããã¨ãããã¨ã ããã
ãã®è¨äºã®åã«ãéååå¦ã®ä¸çãHaskellã§æ§ç¯ãããã¨ã試ã¿ããé£ç¶ç³»ã«ã¤ãã¦ã¯ã¾ã 説æã®éä¸ã§ãããããã®åºæ¬ã¨ãªãé¢æ£ç³»ã«ã¤ãã¦ã¯å®æãã¦ãããéååå¦ã¯ç©çã®ä¸çã§ãé£ããåéã®ä¸ã¤ã ãæ¦å¿µçã«è¤éãªä¸çãè¨è¿°ãããã¨ããã¨ãã¨ã¦ããæ½è±¡åº¦ã®é«ãããã°ã©ãã³ã°è¨èªãå¿
è¦ã¨ããã
ç¾å¨ã®Haskellã¯ãåè«(category theory)ã¨ããæ°å¦ãå¿ç¨ããããã°ã©ãã³ã°è¨èªã§ãããä»ã®å¦åã¨æ¯è¼ããã¨ãæ°å¦ã¯æ½è±¡åº¦ãé«ããåè«ã¯ããã®ä¸ã§ãæãæ½è±¡åº¦ãé«ãåéã®ä¸ã¤ã§ããï¼åè«ãããæ½è±¡åº¦ãé«ãã®ã¯æè¿è©±é¡ã«ãªããã¨ãå¤ããã¢ããã¼åçè«ã ããã®çè«ãããã°ã©ãã³ã°ã®ä¸çã§ä½¿ãããããã«ãªãã¨ãããã°ã©ã ã®è¨¼æã¯ãã£ã¨ç°¡åã«ãªãã¨äºæ³ãã¦ããï¼ã
Haskellã¯æ½è±¡åº¦ãã¨ã¦ãé«ãã®ã§ãå¿ç¨åéã«é©ããæ çµã¿ãæä¾ããã®ã«ã¨ã¦ãé©ãã¦ãããéååå¦ã®ãããªé«åº¦ãªç©çæ¦å¿µããHaskellãç¨ãããã¨ã§ãéååå¦ç¨ã®ãã¬ã¼ã ã¯ã¼ã¯ãå²åã¨ç°¡åã«æä¾ãããã¨ãã§ãããã¨ã¯ãã£ã¦ããéååå¦ã¨åè«ã¨Haskellã®3ã¤ãç解ãã¦ããªããã°ãªããªãã®ã§ãã¼ãã«ã¯é«ããããã§ããããããã«ç²¾éãã¦ããã°åççãªæéã®ä¸ã§å®æããããã¨ãã§ãããããããä»ã®è¨èªãC++ãJavaã§ã¨è¨ãããã¨äºã®è¶³ãè¸ããåãæããæ°ã«ããªããªããæ¬æ ¼çãªä½æ¥ãå§ããåã«æºåãããã®ãå¤ããã¦ãæéããããããã ããè¯ããã®ãã§ããä¿è¨¼ããªãã
ããã°ãè¦ã¦ããã¨ãHaskellã«æ«æãã人ãå¤ããæããã¯ããã®åºæ¬ã¨ãªã£ã¦ããæ¦å¿µãå³ã¡ãåè«ãç解ãã¦ããªãããã ã¨æãããã®ã§ãåè«ã«ã¤ãã¦ãããä¸åº¦èª¬æãã¦ã¿ããã¨æãã
Bartosz Milewskiã¨ããæ¹ãç¥ã£ã¦ããã ãããã Haskellãåè«ã«é¢é£ããããã°ãæ¤ç´¢ããã¨æã è¦ãããååã ã
ããã°ã®プロファイルã«ããã°ããã¼ã©ã³ãã§æè²ãåããçè«ç©çã§å士ã®å¦ä½ãæä¸ããã¦ããããã®å¾ã欧米ã§ãã¹ãã¯ãçµé¨ãããã¤ã¯ãã½ããã§æ¤ç´¢ã¨ã³ã¸ã³ã®éçºãè¡ã£ãããã ãä¼ç¤¾ã®æ¹ãã¤ã³ã¿ã¼ããããã¸ãã¹ã«æ¶æ¥µçã§ãã£ããã¨ãããããã¾ããããªãã£ãããã§ããããã®å¾ãReliable Softwareã¨ããä¼ç¤¾ãç«ã¡ä¸ããç¾å¨ã¯ãã¯ã·ã³ãã³å¤§å¦ã®æ å ±ç§å¦ã®å¤§å¦é¢ã«å¨ç±ãã¦ããã¨ã®ãã¨ã§ãããåçãè¦ãéãã§ã¯ãããç¨åº¦ãæ³ãè¡ã£ã¦ããããã«è¦ããã
å½¼ããã·ã¢ãã«ã§ãããã°ã©ãã¼ã®ããã«ã10週間のコースãéå¬ä¸ã§ãããè¬ç¾©åã¯ãCategory Theory for Programmersã§ãããè¬ç¾©ã®å 容ã¯YouTubeで紹介ããã¦ãããã¾ããæ¸ç±ã§ã®åºçãæãã§ããããã§ã途中までの原稿ãããã°ã«æ²è¼ããã¦ããã
ãã¦ãHaskellãçããã«å§ããçç±ãããå°ã詳ãã説æãããã
ããã°ã©ãã³ã°ãå¦ãã§æåã«æ¸æãè¨è¿°ã¯
\begin{eqnarray}
a=a+1
\end{eqnarray}
ã ããã¨æããæ¹ç¨å¼ã®è¨è¿°ã«æ
£ãã¦ãã身ã«ã¯
\begin{eqnarray}
3x=2x+1
\end{eqnarray}
ã¨ããè¨è¿°ã¯æµæãªãåãå
¥ãããã¨ãã§ããã左辺ã®\(3x\)ã¨å³è¾ºã®\(2x+1\)ã¯çããã¨è¨´ãã¦ããããã®æã\(x=1\)ã ã¨ç解ã§ãããããããåãããã«èããã¨ãã\(a=a+1\)ãæºãã\(a\)ã¯ãªããã¨ãããã¨ã«ãªãã
ããã°ã©ãã³ã°ãã¦ãã¦åºä¼ããã®æ©ã¾ããè¨è¿°ãç解ããããã«ã¯ãã³ã³ãã¥ã¼ã¿ã®ãã¨ãããå°ã詳ããç¥ã£ã¦ããå¿ è¦ããããã³ã³ãã¥ã¼ã¿ã«ã¯ããã»ããµã¨ã¡ã¢ãªããã£ã¦ãããã»ããµã¯è¨ç®ããã¡ã¢ãªã¯ãã¼ã¿ãè¨æ¶ããï¼æ£ç¢ºã«è¨ãã¨ãããã°ã©ã ãããã«è¨æ¶ãããï¼ãã¡ã¢ãªã«ã¯ãçªå°ãã¤ãã¦ãã¦ããã¼ã¿ãåãåºãæãããã¼ã¿ãæ ¼ç´ããã¨ããããã®çªå°ãç¨ãããããã»ããµã¯ã³ã³ããã¨ã³ã¹ã¹ãã¢âã®ãã£ãã·ã¥ã¬ã¸ã¹ã¿ã¼ã¨åãå½¹å²ããããããã»ããµã«ã¯ãã¬ã¸ã¹ã¿ã¼ãããããã¼ã¿ãä¸æçã«è¨æ¶ãããã¨ãã§ãããã¾ããã¬ã¸ã¹ã¿ã¼ã®ãã¼ã¿ã«å¯¾ãã¦ååæ¼ç®ãè¡ããã¨ãã§ããããã®æã足ãæ°ãå¼ãæ°ãæããæ°ãããã¯å²ãæ°ãªã©ã¯ãã¡ã¢ãªã¼ããèªã¿ã ããã¡ã¢ãªããèªã¿ã ããããã¼ã¿ã使ã£ã¦ãã¬ã¸ã¹ã¿ã«ãããã¼ã¿ã«å¯¾ãã¦æå®ãããæ¼ç®ãè¡ãããã®çµæã¯çªå°ãæå®ãã¦ã¡ã¢ãªã«è¨æ¶ãããã¨ãã§ããã
\(a=a+1\)ã¯ã\(a\)ã¨ããååã§å¼ã°ãã¦ããçªå°ãããããã«æ ¼ç´ããã¦ãããã¼ã¿ãåãåºãããããããã»ããµã®ã¬ã¸ã¹ã¿ã«ç§»åããã次ã«ã¬ã¸ã¹ã¿ã®å 容ã«\(1\)ãå ãã(\(1\)ã¨ããå¤ã¯ã¡ã¢ãªã®ã©ããã«ãã¾ããã¦ãã¦ãããããåãåºãã¦ç¨ãã)ãããã¾ã§ã®æç¶ãããå³è¾ºã§ç¤ºããã¦ãããå³è¾ºã®å¦çãçµäºããã¨ã左辺ã®å¦çã«å ¥ããã¬ã¸ã¹ã¿ã®å 容ã\(a\)ã¨ããååã§å¼ã¹ãã¦ããçªå°ã«è¨æ¶ããã
ããã°ã©ãã³ã°ã§ç¨ããè¨è¿°ã¯ãé常ã¯ãæ°å¦ã§ç¨ãããã®ã¨ç°ãªã£ã¦ãããã¨ãå¤ãããã®ãããã³ã³ãã¥ã¼ã¿ã®æ§é ãã³ã³ãã¥ã¼ã¿ã®å é¨ã§ã®å¦çãç´ ç´ã«è¨è¿°ããã¢ã»ã³ããªè¨èªãå¦ã°ãªãã¨ãåå¦è ã¯ç¬ç¹ã®è¨è¿°ããªããªãç解ãããã¨ãã§ããªãã
\(a\)ã¯å¤æ°ã¨å¼ã°ããããå¤æ°ã®å¤ãå¤ãããã¨ã許ããã¦ãããã®ããã¥ã¼ã¿ãã«(mutable)ã¨ãã(ããã§ãªããã®ãã¤ãã¥ã¼ã¿ãã«(immutable)ã¨ãã)ãå¤ãã®ããã°ã©ãã³ã°è¨èªã¯ãå¤æ°ãã¡ã¢ãªã®æ ¼ç´å ´æã表ãã¦ããããã«ããã¥ã¼ã¿ãã«ã§ããã
ããããã³ã³ãã¥ã¼ã¿ãåºã使ãããããã«ãªãã«ãããã£ã¦ãã¢ã»ã³ããªè¨èªã§ã¯ããã°ã©ãã³ã°ãã«ããã®ã§ãããããé«ç´è¨èªã¨å¼ã°ãããã®ãéçºããããããã°ã©ãã³ã°ã®ä¸çã§ãæ½è±¡åãè¡ãããããã«ãªããæ½è±¡åã¨ã¯ãç°ãªã£ã¦ããã¨æãããè¤æ°ã®ä¸çã®ä¸ãããå ±éããæ§è³ªãè¦ã¤ãåºãä½æ¥ã§ãããæ½è±¡åãããã¨ã«ãã£ã¦ãããã¾ã§å¥ã ã®ããã°ã©ã ã¨ãã¦å®è£ ããã¦ãããã®ããå ±éããé¨åã¯åãããã°ã©ã ã§å®ç¾ã§ããããã«ãªããéçºè²»ãä¿¡é ¼æ§ã®åä¸ã«ã¤ãªããã
å種ã®é«ç´è¨èªãåºãä¸ã§ããªãã¸ã§ã¯ãæåã®æ¦å¿µã¯å¤§ããªç»æã§ãã£ããããã§ã¯ãããã°ã©ã ã¯ãªãã¸ã§ã¯ãã®éã¾ãã§ããªãã¸ã§ã¯ãéã§ã¡ãã»ã¼ã¸ãåã渡ããã¨ã§å¦çãé²è¡ããããªãã¸ã§ã¯ãã¯ã¡ãã»ã¼ã¸ãåãåãã¨ããã®å¦çãè¡ãããã®å¦çã¯å¤é¨ã«å¯¾ãã¦ã¯é è½ããã¦ããããã®ããããã£ã¨è¯ãæ¹æ³ãè¦ã¤ããã°ãå¦çã®ä¸èº«ãèªç±ã«å¤æ´ã§ããã¨ããç´ æ´ãããå©ç¹ãæãã¦ããããªãã¸ã§ã¯ãæåã®æ¦å¿µã¯ãæå·§çãªããã°ã©ãã³ã°ã®ä¸çãç§å¦çã»å·¥å¦çã«ããã¨ããä¸ç¿¼ãæ ã£ããåèªèº«ãã¨ã¦ãè¯ãããã°ã©ãã³ã°ã¹ã¿ã¤ã«ã ãªã¨èããæ å ±ç§å¦é¨ãè¨ç«ããã¨ãã«ã1å¹´çããJavaãå¦ã¹ãããã«ããã
ããããå¤æ°ã¯ãã¥ã¼ã¿ãã«ã§ãã£ãããã«ã並è¡å¦çãçãã«ãªãã«å¾ã£ã¦ãã®åé¡ç¹ãæµ®ã彫ãã«ãªã£ã¦ããããªãã¸ã§ã¯ãæåã§ã¯ããªãã¸ã§ã¯ãã¯ç¶æ ãæãããããã¦ãç¶æ ã¯ãã¥ã¼ã¿ãã«ã§ãããç¶æ ã®å¤æ´ã¯ãªãã¸ã§ã¯ãå é¨ã®å¦çã§ãããããé è½ãããå¤é¨ããã¯è¦ããã¨ãã§ããªãã並è¡å¦çã§ã¯ããªãã¸ã§ã¯ããè¤æ°ããåæã«ã¢ã¯ã»ã¹ããããã¨ã許ããå³ã¡ãè¤æ°ã®ãã®ãç¶æ ãå ±æããããã®çµæãåæã«ç¶æ ã®å¤æ´ãè¦æ±ããããã¨ããããããã¯ã競åã¨å¼ã°ããåé¡ã§ãé©åã«è§£æ±ºãããã¨ããã¨å¤§å¤é¢åãªãã¨ã«ãªãã解決ãææ¡ããè«æãããããåºçããã¦ãããã¨ãããé£ãããåããã
å®éãè¾ãçµé¨ããããWebãç¨ãã¦ãçµçã«ãããã社å¡ã®ã ãããã¢ã¯ã»ã¹ã§ããä¼è¨ã·ã¹ãã ã2000å¹´ã®åãããã«éçºãããããã¯ãæéé ãã®ãªãä¼è¨æ å ±ãå¾ãããã¨ãããã¨ã売ãã«ããã·ã¹ãã ã§ãã£ãããã®ããããã©ã³ã¶ã¯ã·ã§ã³ãçããã¨ããä¼è¨ãã¼ã¿ãç¬æã«ãããåæ ãããã¨ãè¦æ±ãããããã®çµæããã¼ã¿æ´æ°ã®ç«¶åãé¿ããã¨ããé¢åãããä½æ¥ãä»ä¸ãããããã¼ã¿ã®æ¸ãæãã¯ä¸ç¬ã§ããã®ã«ãããããããæ¸ãæããããã®å®å ¨æ§ãä¿éããããã«ãä½åãªæ²¢å±±ã®ããã°ã©ã ãå¿ è¦ã¨ãããç¡äºã«å®æã¯ããããããäºåº¦ã¨é¢ããããã¯ãªãã¨ãæã£ãã
Haskellã¯ã¤ãã¥ã¼ã¿ãã«ã§ãããå¾ã£ã¦ããªãã¸ã§ã¯ãæåè¨èªãæã£ã¦ãã並è¡å¦çãè¡ãä¸ã§ã®åé¡ç¹ã¯åé¿ãããããã ãå¤æ°ã®å¤ãå¤ãããã¨ã«é¦´æãã§ããããã°ã©ãã¼ã¯æåã¯æ¸æããã¨ã¨æããå¤æ°ã便å©ã«å¤ç¨ãã¦ãããã¨ã¨æãããã®ã§ãæ足ãããããããã«æåã¯èº«åãã§ããªããããããªããããã°ã©ã ãå帰çã«è¨è¿°ããã¨ããã®ããã¤ãã¥ã¼ã¿ãã«ãªè¨èªã§ã®è§£æ±ºçã§ãããããããããã«æ £ããã«ã¯æéã®ããã人ãå¤ãã§ãããã
ããããæ½è±¡åã¯ã¨ã¦ã大åãªæ¦å¿µã§ãããæ½è±¡åãããã¨ã«ãã£ã¦ãå¿ è¦ã§ã¯ãªããããªç´°ããããåé¡ããåé¿ããããã®æ¬è³ªã ãã«éä¸ã§ããããã«ãªããããã«ãããéçºã®æéã¯ç縮ãããä¿¡é ¼æ§ã¯ä¸æ®µã¨é«ã¾ãããããã°ã®ãããªãããã°ã©ã éçºãç®æããã¨ãã§ããããã«ãªãã
ããã§ã¯ã次åããåè«ã®è©±ããå§ãããã