æ¬è¨äºã®ç®ç 解説 Stateã¢ããã®å®ç¾© ã²ã¨ã¤ã®è£é¡ ã³ã¼ããèªã¿è§£ãã¦ãã ã¾ãã¯é¨åçã« ããã¦å ¨ä½ã¸ ã¾ã¨ã æ¬è¨äºã®ç®ç Stateã¢ããã®æåãå®ç¾©ããå°åºããã. ãããæ¬è¨äºã®ç®æ¨ã§ã. Stateã¢ããã«ã¤ãã¦èª¿ã¹ãã¨, ããã¤ãã®è¨äºãããããã¾ã. ããã§ã¯Stateã¢ããã®ä½¿ãæ¹ã¨ãã¦ä»¥ä¸ã®ãããªãµã³ãã«ã³ã¼ããå¼ãåãã«åºããããã¨ãå¤ãã§ããã. import Control.Monad.State pickHead :: State [Int] Int pickHead = do x:xs <- get -- ç¶æ (æ´æ°ã®ãªã¹ã)ãåå¾ put xs -- å é 以å¤ã®é¨åãæ°ããªç¶æ ã¨ãã¦ã»ãã return x -- å é ãè¿ã sumHeads :: State [Int] Int sumHeads = do x <- pickHead -- å é ãåå¾
{{#tags}}- {{label}}
{{/tags}}