ãã¿ã¼ã³ã¬ã¼ãã¨Gaucheã®util.match
æè¿ã®Haskellã«ã¯パターンガードã¨ãããã®ããããããï¼
{-# LANGUAGE PatternGuards #-} addLookup alist x y | Just m <- lookup x alist , Just n <- lookup y alist = m + n | otherwise = 0 main = print $ addLookup [(1, 2), (3, 4)] 1 3 -- => 6
Gaucheã® util.match ã§ã©ã®ããã«æ¸ãããèãã¦ã¿ãï¼ä¸ã®ã³ã¼ãã§ã¯ä½¿ã£ã¦ãªããã©ï¼ã¬ã¼ãã®å¾ã®å¼ããåã«æç¸ããå¤æ°ãè¦ããã®ã§ãã®ããã«ããï¼
(use util.match) (define add-assoc (match-lambda* ((alist x y) (match (assoc x alist) ((_ . m) (=> next) (match (assoc y alist) ((_ . n) (+ m n)) (_ (next)))) (_ 0))))) (define (main args) (print (add-assoc '((1 . 2) (3 . 4)) 1 3))) ; => 6
ã§ãããã©ä»ä¸ã¤ãªæãï¼è¤æ°ã®å¼ã«é 次ããããããã ããªã match-let*
ã使ãããã©ï¼ããã¯ãããã«å¤±æããã¨ä¾å¤ãé£ãã§ããã®ã§ãã£ããããªãï¼ä¸æ¦ãªã¹ãã«çºããæ¹æ³ã§ã¯åã®å¤æ°ãè¦ããªãï¼
ä½ãåé¡ãªã®ã ããï¼match
ã®ãã¹ããç°¡æ½ã«æ¸ãããã¯ããããã°ããã®ããªãï¼ä¸è¨ã®ä¾ã ã¨ï¼match-let*
ã«ãããã«å¤±æããå ´åãæ¸ããã°ããã ãã§ããªããã£ããããæ°ãããï¼
(19:29 ã³ã¼ããããããã£ãã®ã§ä¿®æ£)