Skip to content

Instantly share code, notes, and snippets.

@dbramucci
Created March 13, 2020 00:25
Show Gist options
  • Save dbramucci/a0d84a701bf40c28e006f5ff2c207132 to your computer and use it in GitHub Desktop.
Save dbramucci/a0d84a701bf40c28e006f5ff2c207132 to your computer and use it in GitHub Desktop.
generators in Haskell without conduits/pipes
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