Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize fibonacci #187

Merged
merged 5 commits into from
Jul 24, 2020
Merged

Conversation

milesfrain
Copy link
Collaborator

@milesfrain milesfrain commented Jul 17, 2020

Fixes #182

@milesfrain milesfrain marked this pull request as ready for review July 17, 2020 17:03
* `fibMemo n = memoize fibFast n`
* `fibMemo = memoize fibFast`
* Move to a `let` or `where` clause inside of `fibFast`.
-}
Copy link
Owner

@JordanMartinez JordanMartinez Jul 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding you correctly, adjusting fibMemo in the above 3 ways will remove the performance benefit of memoization.
Could we convert those examples to code, add them as statements to main but leave those statements commented out with a header above explaining why?
For example:

main :: Effect Unit
main = do
  log $ i "basic fib result" $ fib 7
  ...
  log $ i "fibSlow result: " $ fibSlow 7

  -- These examples type check and seem
  -- to incur the performance benefits of memoization. 
  -- However, they do not. Uncomment them to see for yourself.
  -- log $ i "fibBroken1 result: " $ fibBroken1 7
  -- ..

I think I'd also prefer that main be immediately below the import statements, so that one can see what will run and then see how they are defined.

Thoughts?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. These are good suggestions. I'll circle back to this task in about a week. Trying to wrap-up the try-purescript enhancements first.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I'll push changes to this PR and merge. If you have feedback on what I've done, feel free to open an issue.

Stay focused on the try-purescript stuff as that's more important.

…ken4

fibBroken4 fails to compile. Not sure whether this is a compiler bug or 
not.
@JordanMartinez JordanMartinez merged commit 5f1eacb into JordanMartinez:master Jul 24, 2020
@milesfrain milesfrain deleted the memoize-fibonacci branch July 24, 2020 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MemoizeFibonacci
2 participants