Haskellã®éçãªåæ¤æ»ã¯å¼·åã§ããï¼ããã°ã©ã ã®å®è¡æã«èµ·ããå¾ããã¹ã¦ã®åé¡ã解決ã§ããããã§ã¯ããã¾ãããä¾ãã°ç¬¬5åã§ææããããã«ï¼ä¾ååãæããªãç¾å¨ã®æ¨æºHaskellã§ã¯ï¼æ¤è¨¼ã§ããåé¡ã®ç¯å²ã«éçãããã¾ããã¾ãï¼FFIã使ã£ã¦å¼ã³åºãå¤é¨é¢æ°ã«ã¯ï¼Haskellã®åæ¤æ»ã¯è¡ãå±ãã¾ãããå®è¡åã«éçã«è§£æ±ºã§ããªãåé¡ã¯ï¼å®è¡æã«åçã«è§£æ±ºããå¿ è¦ãããã¾ãããã®ããã®æ段ãæä¾ããã®ãä¾å¤å¦çã§ãã ä¾å¤å¦çã«ã¤ãã¦ã¯ï¼ããã¾ã§ä½åº¦ãæççã«èª¬æãã¾ãããï¼å ¨ä½åãã¾ã¨ãã¦è§£èª¬ãããã¨ã¯ããã¾ããã§ããã次å以éã«FFIã¨ä¾å¤å¦çã¨ã®é¢ä¿ã«ã¤ãã¦èª¬æããåã«ï¼ä»åã¯Haskellã®ä¾å¤å¦çã«ã¤ãã¦ãã¡ãã¨èª¬æãã¦ããã¾ãããã ä¾å¤å¦çã®ä»çµã¿ã¯ï¼GHC 6.10ã«åé²ãããbase 4.0ããã±ã¼ã¸ä»¥éã§å¤§ããå¤æ´ããã¾ããbaseããã±ã¼ã¸ã¯ããã¡ã¯ãã»ã¹ã¿ã³ã
Haskell ã§ã®ä¾å¤å¦çã®ç¶ããä»æ¥ã¯ä¾å¤ãæãããï¼ throwIO IO ã®ä¸ã§ãä¾å¤ãæããã«ã¯ throwIO ã使ãã¾ãã throwIO :: Exception e => e -> IO a Exceptionåã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã渡ãã°ããããã§ããControl.Exceptionã®ããã¥ã¢ã«ãèªãã¨ãExceptionåã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦ãIOException ã ArithException ãããã®ãåããã¾ãã ãã®ä¸ããããã¼ã¿æ§æåãå ¬éããã¦ãããã®ãæ¢ãã¦ã¿ã¾ããããArithException ã¯ããã¼ã¿æ§æåãå ¬éãã¦ãã¾ããããã®ä¸ã¤ã§ãããOverflow ã¨ããä¾å¤ãæãã¦ã¿ã¾ãããã > :m Control.Exception Control.Exception> throwIO Overflow *** Exception:
ãªãã¤ã¼ãæ°ã30ãè¶ ããã®ã§ãHaskell ã§ã®ä¾å¤å¦çã«ã¤ãã¦èª¬æãã¾ããåãæãã«ãHaskell ã§ã®ä¾å¤å¦çãåããã«ããã®ã«ã¯ã2ã¤çç±ãããã¾ãã ã©ã¤ãã©ãªã®æ··ä¹± ãã©ãã¤ã ã®éã æ´å²ççµç·¯ã«ãããPrelude ã«ã Control.OldException ã«ã Control.Exception ã«ã catch ãããã¾ããæ´å²ççµç·¯ã説æããã®ã¯é¢åãªã®ã§ãããã ãè¦ãã¦ä¸ããããControl.Exception ã ãã使ã£ã¦ããã以å¤ã¯å¿ããã ããããç´ç²é¢æ°å㧠catch ã¨ãè¨ããã¦ãåãããªãããããã¾ãããHaskell ã§ã¯ãç´ç²ãªé¢æ°ã¨ IO ã¨ã§ã¯ãä¾å¤å¦çã®æ¹æ³ãç°ãªãã¾ããå½ä»¤ç㪠catch ãªã©ã使ãã®ã¯ IO ã§ããç´ç²ãªé¢æ°ã«ã¯ Maybe ããEither ã使ãã¾ãã ç´ç²ãªé¢æ° ç´ç²ãªé¢æ°ã§ã¯ãååã¨ãã¦ä¾å¤ãæãã¦ã¯ã
@tanakh 師㨠@nushio ã«ããä¼è©±ã横ããã¡ã¢ãããã®ã - Haskellã§ã¯ã¨ã©ã¼ã¯åã«è¿½ãåºãã®ãæ£æ»æ³ãPureãªè¨ç®ããErrorãé£ã³åºã¦ããã®ã¯å¯¾å¦ãããããªãã®ã§é¿ããã¹ãã - åã«è¿½ãã ãã¨æçµçã«ãã¹ã¦ã®æä½ãä¾ãã°Monadã®ä¸ã§è¡ããããã¨ã«ãªãããããã©ãèãããã ç¶ããèªã
ååã¾ã§ã®ã¨ã³ããªã¼ã¯ãã¡ã BDD on Haskell ã®çºã®ãã£ã¬ã¯ããªæ§æãèãã BDD on Haskell ãã¥ã¼ããªã¢ã« ãã®0 Haskell ã®æµ®åå°æ°ç¹å°æ°ã®åå¤æ¯è¼ã«ã¤ã㦠BDD on Haskell ãã¥ã¼ããªã¢ã« ãã®1 : HUnit 㧠TDD ã BDD on Haskell ãã¥ã¼ããªã¢ã« ãã®2 : QuickCheck ã§ã©ã³ãã ãã¹ã ååã¾ã§ã§ï¼ã»ã¼ TDD BDD ã®åºæ¬ã¯æ¸ããã®ã ãã©ï¼ä»åã¯ä¾å¤ã«ã¤ãã¦ï¼ Haskell ã®ä¾å¤å¦çHaskell ãæ®éã®è¨èªããããï¼ä¾å¤å¦ç㯠throw try catch 使ããï¼ããã© IO ã絡ãã§ããå ´åã§ãªãã¨ãã¾ãæç¨ã§ã¯ãªãå°è±¡ï¼ throw try catchHaskell ã® try catch throw finally 㯠Control.Exception ã¢ã¸ã¥ã¼ã«ã§å®ç¾©ãã
ï¼ãã®è¨äºã¯Haskell Advent Calendar jp 2010ã®ããã«æ¸ããã¾ããï¼ Haskellã§ã¯ã¨ã©ã¼å¦çã«ä¾å¤ãç¨ãããã¾ãï¼Maybeã¢ãããErrorã¢ãããç¨ãããã¾ãããããã§ã¯ä¾å¤ã«ç¦ç¹ããã¦ã¾ãï¼ã ä¾å¤ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®è©± Haskellã«ããä¾å¤ãæ±ãããã«try, catch, finallyãªã©ãç¨æããã¦ãã¾ããä»ã®å¤ãã®è¨èªã§ã¯ãããã¯æ§æã¨ãã¦ç¨æããã¾ãããHaskellã§ã¯IOã¢ãããå¼æ°ã«ã¨ãé¢æ°ã«ãªã£ã¦ãã¾ãã try :: Exception e => IO a -> IO (Either e a) catch :: Exception e => IO a -> (e -> IO a) -> IO a finally :: IO a -> IO b -> IO a tryã¯IOã¢ã¯ã·ã§ã³ãå¼æ°ã«ã¨ãããããå®è¡ããçµæãæ£å¸¸ã«å¤ãè¿
Haskellã§å®è£ ããé¢æ°ã®å¤ãã§ã¯ããããã Java ã® try/throw/catch/finally ã¯å¿ è¦ã«ãªãã¾ãããããããIO ã絡ãã§ããã¨è©±ã¯å¥ã§ããç°å¸¸ãªç¶æ ã«é¥ã£ãããthrow ãã¦ãããã¬ãã«ã«æ»ãæ¹ããã³ã¼ãããã£ããæ¸ããå ´åãããã¾ãã Java ã§è¨ã try/catch Haskellãåå¼·ãã¦ããã¨ãããã«catchãè¦ä»ããã¾ããcatch ã¯ãã¬ãªã¥ã¼ãã§å®ç¾©ããã¦ãã¦ã以ä¸ã®ãããªåãæã£ã¦ãã¾ãã catch :: IO a -> (IOError -> IO a) -> IO a 第ä¸å¼æ°ã®ã¢ã¯ã·ã§ã³ã®ä¸ã§ä¾å¤ãçããã¨ã第äºå¼æ°ã®é¢æ°ãè£è¶³ãã¾ããã¤ã¾ãã第äºå¼æ°ã Java ã§ãã catch ãããã¯ã«ãããã¾ãããããã風ã«ä½¿ãã¾ãã catch ä½ããã®ã¢ã¯ã·ã§ã³ (\e -> ä½ããã®ä¾å¤å¦ç) æ Monadius ãèªãã
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}