Summary

  • This could be used to memoize a recursive function for example.
  • Dynamic dispatch can be desugared to continuation passing: a functional concept.
  • This style of continuation passing can be denoted as “Open Recursion” because the recursive calls are left open to be overridden.

Memoization Using Inheritance


Summary

  • This paradox allows a proof of any statement, no matter how absurd.
  • Some statically typed programming languages allow for basic logical statements to be made and subsequently proven. …


It’s a switch. Use it.

Summary

  • Many of the limitations can be overcome by using either dynamic dispatch, or the visitor pattern depending on your use case.
  • In languages that support sum types natively, consider using those instead of the visitor pattern.

Introduction


Summary

  • An alternative derivation of DRY is presented, that aims to alleviate some of these limitations
  • Programs are made up of functions, and to make functions maximally reusable they should:
    - Have the most lenient preconditions
    - Have…


Recently I made a game and entered it into the Github Game Off 2019. The premise of the game is that there are a series of cows that run around following rules. The aim in the earlier levels is to get all of the cows into a green area. …


Summary:

  • A regular data structure can be converted into a persistent one by replacing instances of Box with Rc, and replacing mutable dereferences with Rc::make_mut.
  • The resulting structure is both more performant and uses less…


Summary

  • In freeform shared mutability, we cannot cache any calculation that depends on a shared mutable entity.
  • If we limit the scope of sharing to code we trust not to invalidate our cache, then…


Summary

  • We cannot have sharing, mutability and “internal consistency”. A program that tries to have all three is provably incorrect.
  • If we want sharing, and mutability but do not need “internal consistency”, we can use a file, a database handle…


Summary

  • A closure with no context is just a function pointer.
  • A closure which has an immutable context belongs to Fn.
  • A closure which has a mutable context belongs to FnMut.
  • A closure that owns its context belongs to…


Summary:

Using “open” recursion:

  • We can separate memoization logic from function logic.
  • We can memoize functions without modifying the syntax of the function.
  • We can make functions generic across multiple types of memoization.

Memoization in Rust.

Andrew Pritchard

The stories I write are a part of a learning journey through life, logic and programming. Share this journey with me.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store