-- Later: combine with IO monad for stable names. import Flatten import Control.Monad.State -- import System.IO.Unsafe -- import System.Mem.StableName ---- Monad versions ---- -- The foldable function wrapped in a State monad with unit output. -- This might only be useful when combined with the IO monad for -- stable names. type DictUpdate n v = State ([v], [(Graph n v, v)]) () dictExtendState :: (Eq v, Eq n) => Graph n v -> DictUpdate n v dictExtendState node = State tx where tx s = ((), dictExtend s node) -- Dictionary accumulation then happens as a side effect of chaining -- the update function above, mapped over the nodes. nameNodesState vars expr = dict where (_, (_, dict)) = (runState $ sequence $ fmap dictExtendState $ nodes expr) (vars,[])