Skip to content

Instantly share code, notes, and snippets.

@berdario berdario/fibs.hs
Created Sep 3, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.