1. ãã¬ãŒã ã¯ãŒã¯ãšã¯äœãïŒ
ãã¬ãŒã ã¯ãŒã¯ãšã¯ãããã°ã©ã ã®åºæ¬ãšãªãæ§é ãæäŸãããœãããŠã§ã¢ã®ããšãæããŸããå ·äœçã«ã¯ãéçºè ãå¿ èŠãšããäžé£ã®ã©ã€ãã©ãªãã¯ã©ã¹ãã€ã³ã¿ãŒãã§ãŒã¹ãªã©ãåãããããã°ã©ã ã®éªšçµã¿ã®ãããªãã®ã§ãããã®ãã¬ãŒã ã¯ãŒã¯ãå©çšããããšã§ãéçºè ã¯ãœãããŠã§ã¢ã®åºæ¬çãªèšèšãæ§é ãæ°ã«ããããšãªããå¿ èŠãªéšåã ããè¿œå ãããä¿®æ£ãããããã®ãå¯èœãšãªããŸãã
1.1. ãã¬ãŒã ã¯ãŒã¯ã®æŠèŠ
ãã¬ãŒã ã¯ãŒã¯ã¯ãåºæ¬çã«ã¯ç¹å®ã®ããã°ã©ãã³ã°èšèªã«åºæã§ããããã®èšèªã«åãããã©ã€ãã©ãªãããŒã«ãéãŸã£ãŠããŸãããœãããŠã§ã¢éçºã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã®åºæ¬çãªèšèšãæ§é ããŒãããèªåã§çµã¿ç«ãŠãã®ã¯éåžžã«æéãšåŽåãèŠããŸãããããããã¬ãŒã ã¯ãŒã¯ãæäŸããåçš®ããŒã«ããã³ãã¬ãŒããå©çšããããšã§ããããã®é¢åãªäœæ¥ãäžéšçç¥ã§ããŸãããããã£ãŠããã¬ãŒã ã¯ãŒã¯ã®æ倧ã®ç®çã¯ãéçºè ã®çç£æ§ãåäžãããããšãšèšããã§ãããã
1.2. ãã¬ãŒã ã¯ãŒã¯ã®ã¡ãªãã
ãã¬ãŒã ã¯ãŒã¯ãå©çšãããšããŸããéçºæéã®ççž®ãšå¹çåãå¯èœãšãªããŸããäžããã³ãŒããæžãã®ã§ã¯ãªãããã¬ãŒã ã¯ãŒã¯ã«çšæãããã©ã€ãã©ãªããã³ãã¬ãŒããã¢ãžã¥ãŒã«ã䜿ãããšã§éçºãå¹ççã«è¡ãããšãã§ããŸãããŸããä»ã®éçºè ãšã®åæ¥ã容æã«ãªããŸãããã§ã«åºæ¬çãªã³ãŒãæ§é ãå®ãŸã£ãŠããã®ã§ãä»ã®éçºè ããã®æ§é ãç解ããã°ããã«éçºã«åå ã§ããŸãã
ããã«ãå質ã®äžè²«æ§ããã¬ãŒã ã¯ãŒã¯ã®å€§ããªã¡ãªããã®äžã€ã§ãããã¬ãŒã ã¯ãŒã¯ãå©çšããã°ãäžè²«ããèšèšãã¿ãŒã³ãã³ãŒãã£ã³ã°èŠåã匷å¶ãããŸãããã®çµæãéçºè ãèšè¿°ããã³ãŒãã®å質ã¯äžå®ä»¥äžãä¿èšŒããããããå質ã®ãã©ãããæããããŸãã
1.3. ãã¬ãŒã ã¯ãŒã¯ã®ãã¡ãªãã
ããããäžæ¹ã§ãã¬ãŒã ã¯ãŒã¯ã«ã¯ããã€ãã®ãã¡ãªããããããŸãããŸããåŠç¿ã³ã¹ããå¿ èŠãšãªãããšãæããããŸããæ°ãããã¬ãŒã ã¯ãŒã¯ãå©çšããããã«ã¯ããã®ãã¬ãŒã ã¯ãŒã¯ç¹æã®èšèšãã¿ãŒã³ãã³ãŒãã£ã³ã°èŠåãAPIãªã©ãç解ãã䜿ããããã«ãªããŸã§ã®åŠç¿ãå¿ èŠã§ãã
ãŸãããã¬ãŒã ã¯ãŒã¯ã«äŸåããéçºãšãªããšãããã¡ãªããããããŸãããã¬ãŒã ã¯ãŒã¯ã¯éåžžã«äŸ¿å©ãªããŒã«ã§ãããããã«æ·±ãäŸåãããšããã¬ãŒã ã¯ãŒã¯ãæã€å¶éãæ¬ ç¹ã«çžããããªã¹ã¯ãååšããŸãããã®ããããã¬ãŒã ã¯ãŒã¯ãéžã¶éã¯ãèªèº«ã®éçºèŠä»¶ãšãã¬ãŒã ã¯ãŒã¯ã®ç¹æ§ããã£ãããšç解ããé©åãªéžæãè¡ãå¿ èŠããããŸãã
2. Haskellãšã¯äœãïŒ
Haskellã¯ã1987幎ã«éçºãéå§ãããéçåä»ãã®çŽç²é¢æ°åããã°ã©ãã³ã°èšèªã§ããçŽç²é¢æ°åèšèªãšã¯ãå šãŠã®èšç®ãé¢æ°ã®è©äŸ¡ãšããŠè¡ãããå¯äœçšãååšããªãèšèªã®ããšãæããŸãããã®ç¹æ§ã«ãããHaskellã®ããã°ã©ã ã¯æ°åŠçãªèšŒæã容æã§ããã°ãå°ãªããé«åºŠãªäžŠååŠçãé 延è©äŸ¡ãå¯èœãšãªããŸãã
2.1. Haskellã®ç¹åŸŽ
Haskellã¯éåžžã«é«åºŠãªæœè±¡åãå¯èœãšããããšãäžã€ã®ç¹åŸŽã§ãããã®æœè±¡åãå¯èœãšããæ©èœãšããŠé«éé¢æ°ãã¢ãããããããããã«ããã³ãŒãã®åå©çšæ§ãé«ããããšãå¯èœã§ãããŸããHaskellã¯éåžžã«é«åºŠãªåã·ã¹ãã ãæã£ãŠããŸããåã¯ã©ã¹ã«ããå€çžæ§ãé«éåãå©çšããããšã«ãããã³ãŒãã®å®å šæ§ãšè¡šçŸåãäž¡ç«ããããšãã§ããŸãã
2.2. Haskellã®æŽå²
1980幎代åŸåã«ãæ§ã ãªé¢æ°åèšèªã®äžãããã¹ãã®éšåãåãå ¥ããŠæ°ããèšèªãéçºãããšããç®çã§Haskellã®éçºãéå§ãããŸããããã以æ¥ãã¢ã«ããã¢ãšæ¥çã®åæ¹ãã泚ç®ãéããçŸåšã§ã¯ããã°ã©ãã³ã°èšèªç 究ã®ããã³ããšã³ããšããŠããŸããããããæ¥çã§ã®ãããžã§ã¯ãéçºã«äœ¿çšããããŸã§ã«è³ã£ãŠããŸãã
2.3. Haskellã®åºæ¬çãªã³ãŒãæ§é
Haskellã®ã³ãŒãã¯æ°åŠçãªé¢æ°ã®å®çŸ©ãšãã®é¢æ°ãçšããè©äŸ¡ããæãç«ã£ãŠããŸãã以äžã«ãç°¡åãªHaskellã®ã³ãŒãã瀺ããŸãã
main = print (factorial 5) factorial 0 = 1 factorial n = n * factorial (n - 1)
äžèšã®ã³ãŒãã¯ãéä¹ãèšç®ããé¢æ°factorialãå®çŸ©ãããã®é¢æ°ãçšããŠ5ã®éä¹ãèšç®ãåºåããããã°ã©ã ã§ããå é ã®mainé¢æ°ãããã°ã©ã ã®ãšã³ããªãŒãã€ã³ããšãªããŸãã
3. Haskellãã¬ãŒã ã¯ãŒã¯ã«ã€ããŠ
ããŠãããããã¯Haskellãã¬ãŒã ã¯ãŒã¯ã«ã€ããŠè©³ããèŠãŠãããŸããããHaskellãã¬ãŒã ã¯ãŒã¯ãšã¯äžäœäœãªã®ã§ããããïŒãŸããããã«ã¯ã©ã®ãããªç¹åŸŽãå©ç¹ãããã®ã§ããããïŒããããé ã«è§£èª¬ããŠãããŸãã
3.1. Haskellãã¬ãŒã ã¯ãŒã¯ã®æŠèŠ
Haskellãã¬ãŒã ã¯ãŒã¯ã¯ãHaskellãšããé¢æ°åããã°ã©ãã³ã°èšèªã§ã¢ããªã±ãŒã·ã§ã³ãäœãããã®ããŒã«ããã¯ã¹ãšãããããã®ã§ããããã䜿ããšãã¢ããªã±ãŒã·ã§ã³éçºãæŽã«å®¹æã«ãªããã³ãŒãã®åå©çšæ§ãé«ãŸããŸãããŸãããã¬ãŒã ã¯ãŒã¯ãªãã§ã¯ã®äžè²«æ§ãšæ§é åãããããããŸããèšã£ãŠã¿ãã°ãããªãã建ç©ã建ãŠãããã®åå°ãšãªãçŽ æãæäŸããŠãããã®ã§ãã
3.2. Haskellãã¬ãŒã ã¯ãŒã¯ã®ç¹åŸŽ
次ã«Haskellãã¬ãŒã ã¯ãŒã¯ã®ç¹åŸŽã«ã€ããŠèªããŸãããããŸãäžã€ãHaskellãã¬ãŒã ã¯ãŒã¯ã¯é«åºŠãªåæ€æ»ãæã£ãŠããŸããããã«ãããCompileæã«ãã°ãé²ãããšãã§ããŸãããŸããHaskellãã¬ãŒã ã¯ãŒã¯ã¯äžŠè¡åŠçãšäžŠååŠçããµããŒãããŠããŸããããã¯ãè€æ°ã®ã¿ã¹ã¯ãåæ¶ã«åŠçããããšãèŠæ±ãããçŸä»£ã®WEBéçºã«ãšã£ãŠå€§å€æçšã§ãã
ä»ã«ããHaskellãã¬ãŒã ã¯ãŒã¯ã¯ãçŽç²é¢æ°åããã°ã©ãã³ã°ãã«åºã¥ããŠèšèšãããŠãããäžå€æ§ãé«éé¢æ°ãªã©ãé¢æ°åããã°ã©ãã³ã°ã®å©ç¹ããã«ã«æŽ»ããããšãã§ããŸããããã«ãHaskellãã¬ãŒã ã¯ãŒã¯ã¯ããŒã¿ãšã¢ã¯ã·ã§ã³ãæèããæ°ããæ¹æ³ãæäŸããéçºè ã«ãšã£ãŠæ°ããªèŠç¹ããããããŸãã
3.3. Haskellãã¬ãŒã ã¯ãŒã¯ãå©çšããã¡ãªãã
æåŸã«Haskellãã¬ãŒã ã¯ãŒã¯ãå©çšããã¡ãªããã解説ããŸããå ã»ã©ã®ç¹åŸŽãããåããããã«ãHaskellãã¬ãŒã ã¯ãŒã¯ãå©çšããããšã§ãéçºè ã¯å®å šãã€å¹ççãªã³ãŒããæžãããšãå¯èœã«ãªããŸãããããŠãããã¯ã¢ããªã±ãŒã·ã§ã³ã®ä¿¡é Œæ§ããã³ä¿å®æ§ãåäžãããŸãã
ãŸãããã¬ãŒã ã¯ãŒã¯ãæäŸããäžè²«æ§ã®ããéçºãã¿ãŒã³ã¯ãããŒã éçºã«ãããŠã³ãŒãã®èªã¿ããããæ¹åããååçãªéçºã容æã«ããŸããããã«ãHaskellãã¬ãŒã ã¯ãŒã¯ã¯ç¹ã«ç§åŠèšç®ãããŒã¿åæãªã©ã®é åã§åšåãçºæ®ãã倧èŠæš¡ã§è€éãªã·ã¹ãã ãã¢ãã«åããããããŸãã
ãããã®ããŸãçµã¿åããã£ãã¡ãªããã«ãããHaskellãã¬ãŒã ã¯ãŒã¯ã¯åŒ·åãªããŒã«ãšãªãåŸãã®ã§ãã
4. Haskellãã¬ãŒã ã¯ãŒã¯ã®äž»èŠãªçš®é¡
Haskellã®äžçã«ãããŠãç¹ã«æåãã€æŽ»çšãããŠãããã¬ãŒã ã¯ãŒã¯ã¯è€æ°ãããŸããããããã®ç¹æ§ãç解ããé©åã«éžæããããšã§ãããéçºå¹çãé«ãŸããŸãã
4.1. Yesod
Yesodã¯ãéçã§åŒ·ãåã®å®å šæ§ã掻ãããªãããå¹ççã«éçºãé²ããããšãç®æãããã¬ãŒã ã¯ãŒã¯ã§ããURLã«ãŒãã£ã³ã°ãããŒã¿ããŒã¹ã®ã¯ãšãªãHTMLã®çæçãWebéçºã®å€æ§ãªåŽé¢ã§åå®å šæ§ã確ä¿ãããŠããŸããããã«ãããã³ã³ãã€ã«æã«ãã°ãçºèŠãããããªã£ãŠããŸãããŸããå¹ççãªå®è¡æéãšå°å®¹éã®ã¡ã¢ãªãããããªã³ããèªããYesodã¯é«ããã©ãŒãã³ã¹ãªWebã¢ããªã±ãŒã·ã§ã³ãäœãããã®åŒ·åãªããŒã«ã§ãã
4.2. Snap
å¥ã®Haskellãã¬ãŒã ã¯ãŒã¯ã§ããSnapã¯ããã®ã·ã³ãã«ããšæè»æ§ãç¹åŸŽãšããŠããŸããSnapã¯å°èŠæš¡ãã倧èŠæš¡ãªWebã¢ããªã±ãŒã·ã§ã³ã補äœããããã®ãã¬ãŒã ã¯ãŒã¯ã§ãããã«ãŠã§ã¢ã®ã¢ãŒããã¯ãã£ãç¹åŸŽã«ãªã£ãŠããŸããç¹ã«ãåå¿è ã«ãšã£ãŠã¯åŠç¿ã³ã¹ããäœããç°¡åã«å§ããããç¹ãé åãšãããŠããŸãã
4.3. ãã®ä»ã®ãã¬ãŒã ã¯ãŒã¯
ããã以å€ã«ããHaskellã®ãã¬ãŒã ã¯ãŒã¯ã«ã¯æ§ã ãªçš®é¡ããããŸããäŸãã°ã軜éã§ã·ã³ãã«ãªScottyãçãªãœãŒã¹ãªWebãµãŒãã¹ãç®æãSpockããã€ã¯ããµãŒãã¹åãã®Misoãªã©ãååšããŸãããããžã§ã¯ãã®ããŒãºã«åãããŠéžæããããšãå¯èœã§ãããããã®ç¹æ§ãç解ããäžã§éžæããã°å¹æçãã€å¹ççãªéçºãæåŸ ã§ããŸãã
5. Haskellãã¬ãŒã ã¯ãŒã¯ã®éžã³æ¹
Haskellãã¬ãŒã ã¯ãŒã¯ãéžã¶éãããã€ãã®èŠ³ç¹ããé©åãªãã¬ãŒã ã¯ãŒã¯ãéžã¶ã¹ãã§ããå ·äœçã«ã¯ããããžã§ã¯ãã®èŠä»¶ããã¬ãŒã ã¯ãŒã¯ã®ããã©ãŒãã³ã¹ããµããŒãç¶æ³ãèæ ®ããããšãéèŠã§ãã
5.1. ãããžã§ã¯ãã®èŠä»¶ã«ããéžæ
ãã¬ãŒã ã¯ãŒã¯ãéžã¶éããŸãæåã«èããã¹ãã¯ãããžã§ã¯ãã®èŠä»¶ã§ããäŸãã°ãWEBã¢ããªã±ãŒã·ã§ã³éçºãè¡ãå Žåãã©ã®ãããã®ã¬ã¹ãã³ã¹é床ãå¿ èŠãªã®ããã¢ããªã±ãŒã·ã§ã³ã®èŠæš¡ã¯ã©ã®çšåºŠã«ãªãã®ãããšãã£ãããšãèããå¿ èŠããããŸãããŸãããããžã§ã¯ãã®ã¹ã±ãžã¥ãŒã«ãéçºã¡ã³ããŒã®ã¹ãã«ã¬ãã«ãéèŠãªèŠçŽ ãšãªããŸãããããã®èŠä»¶ãæ確ã«ããããã«æé©ãªãã¬ãŒã ã¯ãŒã¯ãéžã³ãŸãããã
5.2. Haskellãã¬ãŒã ã¯ãŒã¯ã®ããã©ãŒãã³ã¹æ¯èŒ
ãã¬ãŒã ã¯ãŒã¯ã®éžæã«ãããŠããã©ãŒãã³ã¹ãéèŠãªèŠçŽ ãšãªããŸããããã©ãŒãã³ã¹ãšã¯ããã¬ãŒã ã¯ãŒã¯ã®åŠçã®å¹çæ§ãéããæããã®ã§ããŠãŒã¶ãŒã«ãšã£ãŠã®äœ¿çšæãå·Šå³ããéèŠãªææšã§ããYesodãSnapãªã©ã®äž»èŠãªHaskellãã¬ãŒã ã¯ãŒã¯ã®éã§ãããã©ãŒãã³ã¹ã®éããç解ããããã«åºã¥ããŠé©åãªãã¬ãŒã ã¯ãŒã¯ãéžã¶ã¹ãã§ããããã©ãŒãã³ã¹ãæ€èšŒããããã«ã¯ãå ¬åŒããã¥ã¡ã³ããŒã·ã§ã³ã確èªããã»ããå®éã«è©ŠããŠã¿ãããšãäžã€ã®æ¹æ³ã§ãã
5.3. ãã¬ãŒã ã¯ãŒã¯ã®ãµããŒãç¶æ³ã®èæ ®
æåŸã«ããã¬ãŒã ã¯ãŒã¯ã®ãµããŒãç¶æ³ãèæ ®ããããšãéèŠã§ãããµããŒãç¶æ³ãšã¯ããã®ãã¬ãŒã ã¯ãŒã¯ãã©ãã ãã¢ã¯ãã£ãã«éçºãæ¹åãè¡ãããŠããã®ãããšã©ãŒãåé¡ãçºçããéã«ã©ãã ãè¿ éã«å¯ŸåŠããŠããããã®ããæå³ããŸãã詳现ãªæ å ±ã¯ãã¬ãŒã ã¯ãŒã¯ã®å ¬åŒãŠã§ããµã€ããã³ãã¥ããã£ããåŸãããšãã§ããŸãã掻çºãªãµããŒãã¯ãé·æçãªãããžã§ã¯ãã«ãããä¿¡é Œæ§ãå®å¿æãæäŸããŸãã
以äžã®ããã«ããããžã§ã¯ãã®èŠä»¶ããã¬ãŒã ã¯ãŒã¯ã®ããã©ãŒãã³ã¹ããµããŒãç¶æ³ã®3ã€ã®èŠ³ç¹ããHaskellãã¬ãŒã ã¯ãŒã¯ãéžã¶ããšã§ãæé©ãªéžæãå¯èœãšãªããŸããããããèæ ®ããªããæ éã«ãã¬ãŒã ã¯ãŒã¯ãéžã¶ããšã§ããããžã§ã¯ãã®æåã«äžæ©è¿ã¥ãããšãã§ããã§ãããã
6. Haskellãã¬ãŒã ã¯ãŒã¯ãçšããéçºç°å¢ã®æ§ç¯
ä»»æã®ããã°ã©ãã³ã°ãã¬ãŒã ã¯ãŒã¯ã䜿çšããããã«ã¯ããã®èšèªã®ç°å¢ãèšå®ããé©åãªãã¬ãŒã ã¯ãŒã¯ãå°å ¥ããæåŸã«ãããžã§ã¯ããå§ããå¿ èŠããããŸãã以äžã§ã¯ãHaskellãšãã®ãã¬ãŒã ã¯ãŒã¯ãå°å ¥ãããããžã§ã¯ããéå§ãããŸã§ã®ã¹ãããã説æããŸãã
6.1. Haskellç°å¢ã®å°å ¥
ãŸãæåã«ãHaskellã®å®è¡ç°å¢ãã»ããã¢ããããŸããããã¯åºæ¬çã«Haskellã®ããã°ã©ã ãåããããã®æºåã§ãããã€ãã®ç°ãªãæ¹æ³ãååšããŸããäžè¬çã«æãæšå¥šãããã®ã¯ãHaskellã®ã³ã³ãã€ã©ã§ããGHCïŒGlasgow Haskell CompilationïŒãšãããã±ãŒãžç®¡çã·ã¹ãã ã§ããcabalã䜿çšããæ¹æ³ã§ãã
# GHCãšcabalã®ã€ã³ã¹ããŒã« $ sudo apt-get install ghc cabal-install
äžèšã³ãã³ãã«ãããHaskellã®åºæ¬çãªéçºç°å¢ãã»ããã¢ãããããŸãã
6.2. ãã¬ãŒã ã¯ãŒã¯ã®å°å ¥
次ã«ãHaskellãã¬ãŒã ã¯ãŒã¯ãå°å ¥ããŸããããã§ã¯äŸãšããŠããããã¬ãŒã ã¯ãŒã¯ã§ããYesodãå°å ¥ããŠã¿ãŸãããããŸãã¯cabalãã¢ããããŒãããããããYesodãã€ã³ã¹ããŒã«ããŸãã
# cabalã®ã¢ããããŒããšyesodã®ã€ã³ã¹ããŒã« $ cabal update $ cabal install yesod
ãããã®ã³ãã³ãå®è¡ã«ãããYesodã®ãã¬ãŒã ã¯ãŒã¯ãå©çšå¯èœãšãªããŸãã
6.3. ãããžã§ã¯ãã®éå§
æåŸã«ãå®éã®ãããžã§ã¯ããéå§ããŸãããã®ã¹ãããã§ã¯ãyesodã³ãã³ãã䜿çšããŠæ°ãããããžã§ã¯ããäœæãããã®ãã£ã¬ã¯ããªã«ç§»åããŸãã
# æ°ãããããžã§ã¯ãã®äœæãšãã£ã¬ã¯ããªã®ç§»å $ yesod init --bare $ cd [ãããžã§ã¯ãå]
以äžã®æé ã«ãããHaskellãã¬ãŒã ã¯ãŒã¯ãçšããéçºç°å¢ãæ§ç¯ãããæ°ãããããžã§ã¯ããéå§ã§ããç¶æ ãšãªããŸãã
7. Haskellãã¬ãŒã ã¯ãŒã¯ã«ããã¢ããªã±ãŒã·ã§ã³éçº
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãHaskellãã¬ãŒã ã¯ãŒã¯ãçšããã¢ããªã±ãŒã·ã§ã³éçºã«ã€ããŠæ·±ãæãäžããŠãããŸãããã
7.1. åºæ¬çãªã¢ããªã±ãŒã·ã§ã³ã®æ§é
ãŸãåãã«ãHaskellãã¬ãŒã ã¯ãŒã¯ã«ãã£ãŠåœ¢æãããåºæ¬çãªã¢ããªã±ãŒã·ã§ã³ã®æ§é ã«ã€ããŠè§ŠããŠãããŸããHaskellã§ã¯ã䞻㫔Model-View-Controller”ïŒMVCïŒãã¿ãŒã³ãçšããããŸããããã¯ãã¢ããªã±ãŒã·ã§ã³ãã¢ãã«ããã¥ãŒãã³ã³ãããŒã©ã®3ã€ã®èŠçŽ ã«åå²ãããããããç¬ç«ããŠæäœããã¡ã³ããã³ã¹ãè¡ãããã®èšèšãã¿ãŒã³ã§ãã
å ·äœçã«ã¯ã ã¢ãã«ã¯ã¢ããªã±ãŒã·ã§ã³ã®ããŒã¿ãšããžãã¹ããžãã¯ãæ åœãããã¥ãŒã¯ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ãŒã¹ã衚瀺ãæ åœããã³ã³ãããŒã©ã¯ã¢ãã«ãšãã¥ãŒã®éã®ããŒã¿ãããŒãå¶åŸ¡ããŸããããã«ãããããŒã¿ã®ç®¡çããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ãŒã¹ã®è¡šç€ºããŠãŒã¶ãŒå ¥åã®åŠçãåé¢ããããšãã§ããã³ãŒãã®åå©çšæ§ãåäžããŸãã
7.2. ã³ãŒãã®æžãæ¹
Haskellãã¬ãŒã ã¯ãŒã¯ã«ããéçºã§ã¯ãç¬ç¹ã®ã·ã³ã¿ãã¯ã¹ãçšããããŸããããã¯çããæ確ã§ãèªã¿ããããã®ã§ããããHaskellã®äººæ°ã®äžã€ã«æ°ããããŠããŸãã
app :: Application app _ respond = do putStrLn "I've done some IO here" respond $ responseLBS status200 [("Content-Type", "text/plain")] "Hello, Web!"
äžèšã¯ãã·ã³ãã«ãªHaskellã®Webã¢ããªã±ãŒã·ã§ã³ã®ã³ãŒãã®äžéšã§ããããããã®æ©èœã«å¿ããåŠçãè¡ãããŠããŸããæ¬æ Œçãªã¢ããªã±ãŒã·ã§ã³éçºã§ã¯ãããã«è€æ°ã®ã¢ãžã¥ãŒã«ã«åå²ãããæ©èœå¥ã«ã³ãŒããæŽçãããŸãã
7.3. å ·äœçãªéçºæé
Haskellãã¬ãŒã ã¯ãŒã¯ãå©çšããéçºæé ã¯ä»¥äžã®ãããªæµãã«ãªããŸãã
ãŸãã¯ãé©åãªãã¬ãŒã ã¯ãŒã¯ãéžã³ããããåºã«æ°ãããããžã§ã¯ããäœæããŸããYesodãSnapãªã©ãã©ã®ãã¬ãŒã ã¯ãŒã¯ãé©åãã¯ãéçºããã¢ããªã±ãŒã·ã§ã³ã®èŠä»¶ããããŒã ã®æè¡åã«ãã£ãŠç°ãªããŸãã
次ã«ãã¢ããªã±ãŒã·ã§ã³ã®åºæ¬çãªæ§é ãæ§ç¯ããŸããããã«ã¯ãåçš®ã®ã¢ãã«ããã¥ãŒãã³ã³ãããŒã©ã®äœæãå«ãŸããŸããMVCã®èšèšãã¿ãŒã³ãé©çšããããšã§ãéçºãåæ»ã«é²è¡ããŸãã
ãããŠãããžãã¹ããžãã¯ãå®è£ ããŸããããã¯ã¢ãã«å±€ã§è¡ãããé¢æ°åã®ç¹æ§ãçãããåŠçãå¯èœã§ããHaskellãã¬ãŒã ã¯ãŒã¯ã§ã¯ãåã·ã¹ãã ã掻çšããããšã§ãã°ãæ©æã«æ€åºããå®å šæ§ã確ä¿ãã€ã€éçºãé²ããããšãå¯èœã§ãã
æåŸã«ãã¢ããªã±ãŒã·ã§ã³ã®ãã¹ããè¡ããŸããããã«ã¯ãŠããããã¹ããã€ã³ãã°ã¬ãŒã·ã§ã³ãã¹ããå«ãŸããŸãããã¹ããè¡ãããšã§ãã¢ããªã±ãŒã·ã§ã³ã®ä¿¡é Œæ§ãé«ãŸãããªãªãŒã¹ã«åããŠã®èª¿æŽãåæ»ã«é²ã¿ãŸãã
8. Haskellãã¬ãŒã ã¯ãŒã¯ã§éçºããã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãæ¹æ³
ã¢ããªã±ãŒã·ã§ã³ãéçºããéã«ããã®æåã確èªããããã®éèŠãªæ段ããã¹ãã§ããããã§ã¯ãHaskellãã¬ãŒã ã¯ãŒã¯ã§éçºããã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãæ¹æ³ã«ã€ããŠè§£èª¬ããŸãããã¹ãã¯ãŠããããã¹ããšã€ã³ãã°ã¬ãŒã·ã§ã³ãã¹ãã«åããŠèããããŸãããããããã®ç¹åŸŽãšå ·äœçãªæ¹æ³ãããã«ãã¹ãããŒã«ã®äœ¿çšæ¹æ³ã詳ããèŠãŠãããŸãããã
8.1. ãŠããããã¹ãã®æ¹æ³
ãŠããããã¹ãã¯ãã¢ããªã±ãŒã·ã§ã³ã现ããéšåïŒãŠãããïŒã«åããŠããããããæ£ããåäœãããã確èªãããã¹ãææ³ã§ããHaskellèšèªã«ã¯è€æ°ã®ã©ã€ãã©ãªãæäŸãããŠããããã®äžã€ã«ãHspecããšããã©ã€ãã©ãªããããŸãããã®ã©ã€ãã©ãªã䜿çšããããšã§ããŠããããã¹ããç°¡åã«å®è¡ããããšãã§ããŸãã
import Test.Hspec main :: IO () main = hspec $ describe "Square of 2" $ it "should be 4" $ do square 2 `shouldBe` 4
äžèšã®ã³ãŒãã¯ã2ã®äºä¹ã4ã§ããããšã確èªããããã®ãŠããããã¹ãã®äžäŸã§ããHspecã©ã€ãã©ãªã䜿ããšããã®ãããªã·ã³ãã«ãªãã¹ãããè€éãªãã¹ããŸã§ãæ§ã ãªãŠããããã¹ããäœæããããšãã§ããŸãã
8.2. ã€ã³ãã°ã¬ãŒã·ã§ã³ãã¹ãã®æ¹æ³
ã€ã³ãã°ã¬ãŒã·ã§ã³ãã¹ãã¯ãè€æ°ã®ãŠããããçµã¿åãããŠå šäœãšããŠã¢ããªã±ãŒã·ã§ã³ãããŸãåäœãããã確èªãããã¹ãã®ããšã§ããHaskellã®ãã¬ãŒã ã¯ãŒã¯ã§ããYesodã§ã¯ããyesod-testãããã±ãŒãžãå©çšããŠã€ã³ãã°ã¬ãŒã·ã§ã³ãã¹ããè¡ããŸããããã«ããããªã¯ãšã¹ããšã¬ã¹ãã³ã¹ã«å¯Ÿãããã¹ããå¯èœã«ãªããŸãã以äžã«ãã®äžäŸã瀺ããŸãã
import TestImport main :: IO () main = unittest $ yit "gets home page" $ do get HomeR statusIs 200
äžèšã®ã³ãŒãã¯ãããŒã ããŒãžïŒHomeRïŒãžã®getãªã¯ãšã¹ãã200ã¹ããŒã¿ã¹ïŒæåïŒãè¿ãããšã確èªããã€ã³ãã°ã¬ãŒã·ã§ã³ãã¹ãã®äžäŸã§ãããyesod-testãã䜿çšããã°ããã®ãããªãªã¯ãšã¹ããšã¬ã¹ãã³ã¹ã«åºã¥ããã¹ããç°¡æã«äœæã§ããŸãã
8.3. ãã¹ãããŒã«ã®äœ¿çšæ¹æ³
Haskellã§ã¯ãHspecãyesod-testã®ã»ãã«ããQuickCheckãTastyãªã©ã®ãã¹ãããŒã«ãæäŸãããŠããŸãããããã¯å匷ããã¹ãã©ã€ãã©ãªã§ãåçš®ã®ã©ã³ãã ãã¹ããããããã£ããŒã¹ã®ãã¹ããæäŸããŸãã
import Test.QuickCheck main :: IO () main = quickCheck $ property $ x -> square x == x * x
äžèšã®ã³ãŒãã¯ãä»»æã®æ°å€xã«ã€ããŠããã®äºä¹ãx*xãšçããããšããã¹ãããQuickCheckã®äžäŸã§ããHaskellã®ãã¹ãããŒã«ã掻çšããã°ãããå¹ççã§æè»ãªãã¹ããå®æœããããšãå¯èœã§ãã
9. ãŸãšã
æ¬èšäºã§ã¯ãHaskellãã¬ãŒã ã¯ãŒã¯ã®è©³çŽ°ãªã¬ã€ããæäŸããŸãããããã§ãHaskellãã¬ãŒã ã¯ãŒã¯ã®ç¹åŸŽãå©çšæ¹æ³ã«ã€ããŠã®ãŸãšããè¡ããŸãããã
9.1. Haskellãã¬ãŒã ã¯ãŒã¯ã®å©ç¹ãšæ¬ ç¹
ãŸããHaskellãã¬ãŒã ã¯ãŒã¯ã®å©ç¹ãšããŠã¯ãéçåä»ããšçŽç²é¢æ°åèšèªãšããŠã®ç¹æ§ããããå®å šæ§ãæããããŸããé¡åãã³ã³ãã€ã«æã«ãã§ãã¯ãããã©ã³ã¿ã€ã ãšã©ãŒãå°ãªããããå®å®ããã¢ããªã±ãŒã·ã§ã³éçºãå¯èœãšãªããŸãããŸããHaskellãã¬ãŒã ã¯ãŒã¯ã®åããç解ããã°ãè€éãªã³ãŒããå¹ççã«æžãããšãã§ãããã®çµæããã©ãŒãã³ã¹ã®åäžãæåŸ ã§ããŸãã
ããããHaskellãã¬ãŒã ã¯ãŒã¯ã®æ¬ ç¹ãç¡èŠã§ããŸãããçŽç²é¢æ°åãšããç¹æ§ãšãç¬ç¹ãªæ§æã¯åŠç¿æ²ç·ããã€ãããŸãããŸããäž»æµã®èšèªã§ããJavaScriptãPythonã«æ¯ã¹ãŠå¯Ÿå¿ããã©ã€ãã©ãªãæ å ±ã®éãå°ãªãããã解決ãã¹ãåé¡ã«é©åãã解çãæ¢ãã®ãé£ããç¶æ³ã«ãªãããšããããŸãã
9.2 ä»åŸã®Haskellãã¬ãŒã ã¯ãŒã¯ã®å¯èœæ§
ããã§ããHaskellãã¬ãŒã ã¯ãŒã¯ã®å¯èœæ§ã¯å€§ããã§ããé¢æ°åããã°ã©ãã³ã°ã¯äžŠåèšç®ãéåæèšç®ã«åŒ·ãããã«ãã³ã¢ãåæ£ç°å¢äžã§ã®å¹ççãªèšç®ãæåŸ ã§ããŸããããã«ãå®å šæ§ã¯ãœãããŠã§ã¢ã®å質åäžã«çŽçµãããšã©ãŒã®å°ãªãããã°ã©ãã³ã°ãå¯èœãšãªããŸãããããã®ç¹æ§ã¯ãããã°ããŒã¿ã®åŠçãåæ£ã·ã¹ãã ã®éçºãä¿¡é Œæ§ã®é«ããœãããŠã§ã¢ã®äœæã«å¯Ÿãæå¹ã§ãã
æå¹çãªå©çšã®ããã«ã¯ãååãªåŠç¿ãšå®è·µãå¿ èŠã§ããä»åŸãHaskellãã¬ãŒã ã¯ãŒã¯ã®é²åãšå ±ã«ãã®å¯èœæ§ã¯åºãã£ãŠããããšã§ããããæ¯éããã®èšäºãäžæ©ç®ãšããŠãHaskellãã¬ãŒã ã¯ãŒã¯ã®è¿·å®®ã«è¶³ãèžã¿å ¥ããŠã¿ãŠãã ããã