Last active
October 30, 2016 14:17
-
-
Save kayhide/f0f802303da6e0f1d1a154704e99222c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Control.Monad.State | |
type CounterState = State Int | |
fivesWithCounter :: CounterState [Int] | |
fivesWithCounter = do | |
modify (+1) | |
fives <- fivesWithCounter | |
i <- get | |
return $ i:fives | |
main :: IO () | |
main = print $ evalState take10 0 | |
where take10 = do | |
fives <- fivesWithCounter | |
return $ take 10 fives |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Control.Monad.State | |
type CounterState = State Int | |
fivesWithCounter :: CounterState [Int] | |
fivesWithCounter = do | |
modify (+1) | |
(:) <$> get <*> fivesWithCounter | |
main :: IO () | |
main = print $ evalState (take 10 <$> fivesWithCounter) 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment