Skip to content

Instantly share code, notes, and snippets.

@berdario
Created September 3, 2018 08:19
Show Gist options
  • Save berdario/870eebc06beee7a87da5d99a63071e2b to your computer and use it in GitHub Desktop.
Save berdario/870eebc06beee7a87da5d99a63071e2b to your computer and use it in GitHub Desktop.
expansion of a recursive fibs impl
scanl f q ls = q : (case ls of
[] -> []
x:xs -> scanl f (f q x) xs)
fibs = 1 : scanl (+) 1 fibs
1 : 1 : (case fibs of
[] -> []
x:xs -> scanl (+) ((+) 1 x) xs)
# fibs is not []
# x:xs becomes 1:fibs
1 : scanl (+) ((+) 1 1) fibs
1 : scanl (+) 2 fibs
1 : 2 : (case fibs of
[] -> []
x:xs -> scanl (+) ((+) 2 x) xs)
2 : scanl (+) ((+) 2 1) fibs
2 : scanl (+) 3 fibs
2 : 3 : (case fibs of
[] -> []
x:xs -> scanl (+) ((+) 3 x) xs)
3 : scanl (+) ((+) 3 2) fibs
3 : scanl (+) 5 fibs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment