ä¼èª¬ã®åèã"Purely Functional Data Structures"ï¼é常 PFDSï¼ã翻訳ãã¾ããã4 ææ«ã«ã¢ã¹ãã¼ãã¯ã³ã´ããçºå£²ããã¾ãã
ã20分でわかる Purely Functional Data Structuresããªã©ãéãã¦æ¥æ¬ã« PFDS ãå¸æãã @kinaba ã¨ã®å ±è¨³ã§ããã¡ãªã¿ã«ç·¨éããã¯ã¢ã¹ãã¼ãã¯ã³ã´ç·¨éé·ã®鈴木嘉平ããã
é¢æ°åããã°ã©ãåãã®ç´¹ä»
ããªã¹ãã®çµåã O(n) ã§é ããªãã¨ããã¾ã¨ããªãã¥ã¼ã¯ã©ããã£ã¦ä½ãã®ãã¨ããã£ãåé¡ã«ä¸åº¦ã¯ç´é¢ãããã¨ãããã¾ããããç´ç²é¢æ°åããã°ã©ãã³ã°ã§ã¯ã©ããã¦ãç¡çãã¨æã£ã¦è«¦ãã¦ãã人ãããã®ã§ã¯ãªãã§ããããã
ãã®æ¬ã®ææ³ã使ãã°ããçµåã O(1) ã®ãªã¹ããããæ¿å ¥ã»åé¤ã O(1) ã®ãã¥ã¼ããªã©ãåã¿ãããªè¨ç®éãéæã§ãã¦ãã¾ãã¾ãããã¡ãããç ´å£çæ´æ°ã使ããã«ãããã15 å¹´åã®èªåã«æãã¦ãããã*1ã
çµåã O(1) ã®ãªã¹ããã»ããã ãã§ããã°ãæ¢åå®è£ ã® Data.Sequence ãããã使ã£ã¨ãã°è¯ãã§ããããããããããåºæ¥åãã®ã½ãªã¥ã¼ã·ã§ã³ã§ã¯å°ãã±ã¼ã¹ãããã¾ãããã¨ãã° Data.Sequence ã¯åå´è¨ç®éãªã®ã§ããªã¢ã«ã¿ã¤ã æ§ãéè¦ã ã¨å°ãã¨ãã
ãã®æ¬ã¯åãªããçµåã O(1) ã®åã®å®è£ æ¹æ³ãã§ã¯ãªãããå¹ççãªç´ç²é¢æ°åãã¼ã¿æ§é ãå®è£ ããããã®æ±ç¨ææ³ããæãã¦ããã¾ããå¹ççãªåããã¥ã¼ã®å®è£ ã¯ããã®ææ³ã®é©ç¨ãã¢ã¨ãã¦èª¬æããã¾ãããªã®ã§ãç¹å®ã®ã±ã¼ã¹ã§å¿ è¦ãªãã¼ã¿æ§é ãããã¨ãªãã°èªä½ã§ããããã«ãªãã¾ãã
ã¨ãããã¨ã§ãé¢æ°åããã°ã©ããç®æããªããã®æ¬ã®å 容ã¯ç¢ºå®ã«æãã¦ããã¹ãã§ããããããã®æ¹ã¯ãã§ã«æãã¦ãã¨æãã¾ããããã³ãããã¯ã¨ãã¦ãæå ã«æ¯éã
Rubyist åãã®ç´¹ä»
è¨ããªãã°ãããã¹ã¦ã®ãªãã¸ã§ã¯ãã freeze ããä¸çã§ãã©ãã¾ã§å¹ççãªãã¼ã¿æ§é ãä½ããããã追究ããæ¬ã§ãã
ç ´å£çæ´æ°ã使ããªãã®ã§ãã¼ã¿æ§é ãå®è£ ããã®ãé£ãããªããã¨ãå¤ãã§ãããéã«ç°¡åã«ãªããã¨ãããã¾ãããã¨ãã°ãæååã®çµåãæ®éã¯ãã¡ã¢ãªã³ãã¼ãçºçããã®ã§é ãã§ããããããããã¹ã¦ã®æååã freeze ããã¦ããã°ãã³ãã¼ã®å¿ è¦ã¯ããã¾ããã2 ã¤ã®æååã並ã¹ãé åã¨ãã¦è¡¨ç¾ããã°ããã§ãï¼ããããå®è£ ã Rope ã¨è¨ãã¾ãï¼ãããããæãã®èãæ¹ãã²ãããæ·±ãã¦ãã£ããããªæ¬ã§ãã
æ¬æ¸èªä½ã¯ Standard ML ã¨ããã馴æã¿ã®èãããªè¨èªã§èª¬æããã¦ãã¦ãRubyist ã«å ¨åã§ããããã§ããæ¬ã§ã¯ãªãã®ã§ããããµã¤ãã® Ruby ããä¸æ©è¸ã¿åºãããæ¹ã¯ ML ç³»ã®æç§æ¸ã¨åããã¦èªãã§ã¿ã¦ããã ããã¨å¬ããã§ãã
ï¼ãRuby でつくる Rubyããèªãã§ãæ¨ã£ã¦ããããé¢ç½ããªï¼ãã¨æã£ããããªäººã¯ç´ 質ããããï¼
è£è©±
ãRuby でつくる Rubyãã¨ã»ã¼åæå ¬è¡¨ã¨ãªã£ããã®æ¬ã§ãããã©ã¡ããラムダノートã®鹿野桂一郎さんã絡ãã§ãããã¾ãã
鹿éããã«ã¯ TAPL ã®çµãããããã PFDS ã®ç¿»è¨³ä¼ç»ãæã¡ããã¦ãã¾ããã鹿éãããã©ã ããã¼ãã®ç¤¾é·ã¨åããã¿ã¤ãã³ã°ã§å度æã¡ãããããã¢ã¹ãã¼ãã¯ã³ã´ã®é´æ¨åå¹³ãããä¼ç»ãã¦ããã¨ããã£ãã®ã§ãç¹ãã§ããã¦ä»åã®åç¥ã«è³ãã*2
ä¸æ¹ãã©ã ããã¼ãã§ããä¼ç»ãªããªã£ããªã¼ã¨æã£ã¦ãããã鹿éãããããã¡ãã£ã¨å¤ãã£ã Ruby å ¥éã£ã¦ã©ãã ãããã¨æã¡ããããããRuby ã§ã¤ãã Rubyãã«ã¤ãªãã£ã¦ããã¾ããï¼非公式あとがきåç §ï¼ã
ã¨ãããã¨ã§
ãRuby でつくる Rubyãã¨åããã¦ãã¿ãªããæ¯éèªãã§ã¿ã¦ãã ããï¼
*1:åèã¯ããããåï¼1998 å¹´ï¼ã«åºçããã¦ããããã§ããã
*2:ããã£ã¨è¨ãã¾ããã PFDS ã®ç¿»è¨³ã容æã§ã¯ããã¾ããã§ãããé 延è©ä¾¡ã® force ã¨ã suspension ã¨ãæå¤ã«å®è¨³ããªãåèªãå¤ãã£ãããã¢ããªèª¤è¨³ãã¡ããã¡ãããã¾ãã¦ããããå ±è¨³ã® @kinaba 殿ãã¬ãã¥ã¢ã¼ã®æ¹ã ã«æããã¦åºçã«ããã¤ãã¾ãããæè¬ã®éãã