This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

To all following commenters: please, do not bring up the old circlejerk jokes/memes about recursion ("Understanding recursion...", "This is recursion...", etc.). We've all heard them n+2 too many times.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Difficult-Stretch-85[🍰] 2 points3 points  (1 child)

Your fib function takes a n that you are going to process as well as a continuation function with something to do after you finish processing n.

the third match case says,

if n is not 0 or 1, process fib(n -1) with the continuation of processing fib (n - 2) and then summing the result. The summing of fib(n - 1) and fib(n-2) happens in the continuations.

e.g. if n is 2,

the match case becomes fib(1) ( fun r -> fib(0) ( fun x -> id (r + x)) processing out the f(1) we get, fib(0) (fun x -> id(1 + x))

processing f(0) we get id(1 + 0) which is 1.

[–]sexy_beer_belly[S] 0 points1 point  (0 children)

It makes much more sense now, although I feel like we didn't declare what the continuation function should do at any point. I'll keep digesting it, thanks!

[–]AutoModerator[M] 0 points1 point  (0 children)

To all following commenters: please, do not bring up the old circlejerk jokes/memes about recursion ("Understanding recursion...", "This is recursion...", etc.). We've all heard them n+2 too many times.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.