Last active
January 7, 2020 13:07
-
-
Save ssanj/27391879721be5a56d8e55c2dbcd7166 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
count :: Int -> IO Int | |
count it | |
| it <= 0 = pure 0 | |
| otherwise = | |
do | |
n <- count (it - 1) | |
pure (n + 1) |
This file contains hidden or 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 cats.effect.IO | |
val count: Int => IO[Int] = { | |
case 0 => IO.pure(0) | |
case it => | |
for { | |
n <- count (it - 1) | |
} yield (n + 1) | |
} | |
count(10000).unsafeRunSync | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does not stack overflow with even large numbers like 1000000. Why?