Created
March 13, 2020 00:25
-
-
Save dbramucci/a0d84a701bf40c28e006f5ff2c207132 to your computer and use it in GitHub Desktop.
generators in Haskell without conduits/pipes
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
def fib(n): | |
a, b = 0, 1 | |
for _ in range(n): | |
a, b = b, a + b | |
return a | |
# fib n = go 0 1 n | |
# where go a _ 0 = a | |
# go a b n = go b (a + b) (n - 1) | |
def fibs(): | |
a, b = 0, 1 | |
while True: | |
yield a | |
a, b = b, a + b | |
#data Generator a = G a (() -> Generator a) | |
#fibs :: Generator Integer | |
#fibs = go 0 1 | |
# where | |
# go :: Integer -> Integer -> Generator Integer | |
# go a b = G a (\() -> go b (a + b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment