Sign in

    adapton

    Moonbit classic adapton implementation

    adapton
    incremental computing
    Download zip
    Version
    0.1.4
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    42

    No dependencies

    #illusory0x0/adapton

    MoonBit implementation of classic adapton

    Classic adapton features:

    • Laziness
      • set does not update immediately, but marks the corresponding dependency graph nodes as Dirty
      • get only updates dependency targets when the dependency source actually changes
    • Dependency graph
      • When the source actually changes, dirty marks nodes that need updating as Dirty
      • When the target is accessed, propagate calls update on nodes that need updating and marks them as Clean
      • Thunk::get automatically builds the dependency graph on first call, with a global target_stack variable to help with construction
    • Memoization
      • The memo part here refers to DCG (Demanded Computation Graph) nodes

    For most scenarios, using the laziness and dependency graph parts is sufficient.

    Spreadsheets do need memoization quite a bit. Memoization is designed to solve the problem of dynamic dependency graphs. GUI application dependency graphs are generally static and relatively small - this is a matter of granularity control.

    Adapton itself is also pure functional programming. Thunk[Unit] will cause computations that depend on it to never update, so you need to write Thunk[State] that always returns the next state to trigger corresponding actions.

    #Warning

    Because MoonBit currently lacks WeakRef, WeakMap, WeakSet, WeakArray, memory leaks will occur, and this becomes more severe when using memoization.

    Incremental computation itself is also quite memory-intensive.

    #Reference

    Source

    trait Source

    Cell

    type Cell[A]

    impl Source for Cell[A]
    impl Eq for Cell[A]
    impl Hash for Cell[A]

    Cell::get

    fn[A] Cell::get(self : Cell[A]) -> A

    Cell::modify

    fn[A : Eq] Cell::modify(self : Cell[A], f : (A) -> A) -> Unit

    Cell::new

    fn[A] Cell::new(value : A) -> Cell[A]

    Cell::set

    fn[A : Eq] Cell::set(self : Cell[A], value : A) -> Unit

    Thunk

    type Thunk[A]

    impl Source for Thunk[A]
    impl Eq for Thunk[A]
    impl Hash for Thunk[A]

    Thunk::get

    fn[A : Eq] Thunk::get(self : Thunk[A]) -> A

    Thunk::new

    fn[A] Thunk::new(thunk : () -> A) -> Thunk[A]

    cell

    fn[A] cell(value : A) -> Cell[A]

    The same as Cell::new

    clear_memo

    fn clear_memo() -> Unit

    memo

    fn[A : Hash + Eq, B] memo(f : (A) -> B) -> ((A) -> Thunk[B])

    memo_rec

    fn[A : Hash + Eq, B] memo_rec(f : ((A) -> Thunk[B], A) -> B) -> ((A) -> Thunk[B])

    thunk

    fn[A] thunk(thunk : () -> A) -> Thunk[A]

    The same as Thunk::new

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io