Advertisement
timput

parameterized Fibonacci-like sequence sharing

Jun 2nd, 2021
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Slow, not sharing properly
  2. f :: Int -> [Int]
  3. f = \k -> let fk = f k
  4.           -- first argument to zipWith is pointfree for sharing to work
  5.           in (42 : 11*k+77 : zipWith (((+ (10*k)) .) . (-) . (*2)) (tail fk) fk)
  6.  
  7. -- Fast, obviously not acceptable
  8. f1 = let fk = f1; k = 1 in (42 : 11*k+77 : zipWith (((+ (10*k)) .) . (-) . (*2)) (tail fk) fk)
  9. f2 = let fk = f2; k = 2 in (42 : 11*k+77 : zipWith (((+ (10*k)) .) . (-) . (*2)) (tail fk) fk)
  10. f3 = let fk = f3; k = 3 in (42 : 11*k+77 : zipWith (((+ (10*k)) .) . (-) . (*2)) (tail fk) fk)
  11.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement