Haskellã§ãã¡ã¤ã«ãªã©ã®ãªã½ã¼ã¹ã®è§£æ¾ãä¿è¨¼ãããã¯ããã¯ã¨ãã¦ããã¼ã³ãã¿ã¼ã³ï¼Loan Patternï¼ããããwithFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO rãªã©ããã®ä¾ã ã ãã¼ã³ãã¿ã¼ã³ã«ããé¢æ°ãè¤æ°ä½¿ã£ãããã°ã©ã ã¯ãç¡åé¢æ°ã®ãã¹ããæ·±ããªãã main = do withFile "src.txt" ReadMode \src -> withFile "dst.txt" WriteMode \dst -> ... ãã®åé¡ã«ã¯ãç¶ç¶ã¢ããContTã使ã£ãããããªè§£æ±ºçãç¥ããã¦ããã main = evalContT do src <- ContT $ withFile "src.txt" ReadMode dst <- ContT $ withFile "dst.txt" WriteMode .
{{#tags}}- {{label}}
{{/tags}}