-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Reify a recursive data structure into an explicit graph. -- -- 'data-reify' provided the ability to turn recursive structures into -- explicit graphs. Many (implicitly or explicitly) recursive data -- structure can be given this ability, via a type class instance. This -- gives an alternative to using Ref for observable sharing. -- -- Observable sharing in general is unsafe (hence the module path name -- Data.Unsafe.Reify), but can be used safely if some simple conditions -- are met. Typically this package will be used to tie the knot with -- DSL's that depend of observable sharing, like Lava. -- -- Providing an instance for MuRef is the mechanism for allowing a -- structure to be reified into a graph, and four examples of this are -- provided. -- -- Version 0.2 of data-reify uses StableNames, and is much faster. -- -- © 2009 Andy Gill; BSD3 license. @package data-reify @version 0.2 module Data.Unsafe.Reify -- | MuRef is a class that provided a way to reference into a -- specific type, and a way to map over the deferenced internals. class MuRef a where { type family DeRef a :: * -> *; } deRef :: (MuRef a) => a -> (DeRef a) a mapDeRef :: (MuRef a, Monad m) => (a -> m Unique) -> (DeRef a) a -> m (DeRef a Unique) data Graph e Graph :: [(Unique, e Unique)] -> Unique -> Graph e -- | reifyGraph takes a data structure that admits MuRef, and -- returns a Graph that contains the dereferenced nodes, with -- their children as Unique rather than recursive values. reifyGraph :: (MuRef s) => s -> IO (Graph (DeRef s)) instance (Functor e, Show (e Int)) => Show (Graph e)