lvish-2.0: Parallel scheduler, LVar data structures, and infrastructure to build more.

Safe HaskellNone




This basic version of memotables is implemented on top of existing LVars without breaking any rules.

The problem is that it cannot do cycle detection, because that requires tracking extra information (where we've been) which is NOT exposed to the user and NOT used


Memo tables and defered lookups

data Memo e s a b

A Memo-table that stores cached results of executing a Par computation.

data MemoFuture e s b

A result from a lookup in a Memo-table, unforced. The two-stage getLazy/force lookup is useful to separate spawning the work from demanding its result.

makeMemo :: (HasPut e, Ord a, Eq b, Show a, Show b) => (a -> Par e s b) -> Par e s (Memo e s a b)

Reify a function in the Par monad as an explicit memoization table.

Memo table operations

getLazy :: (HasPut e, HasGet e, Ord a, Eq b) => Memo e s a b -> a -> Par e s (MemoFuture e s b)

Begin to read from the memo-table. Initiate the computation if the key is not already present. Don't block on the computation being complete, rather, return a future.

getMemo :: (HasPut e, HasGet e, Ord a, Eq b) => Memo e s a b -> a -> Par e s b

Read from the memo-table. If the value must be computed, do that right away and block until its complete.

force :: MemoFuture e s b -> Par e s b

This will throw exceptions that were raised during the computation, INCLUDING multiple put.