I wanted to use DotM to build up a transformer stack so I could do something like this:
newtype StashStore s a = StashStore { runStashStore :: ExceptT String (StateT s (DotM NodeId)) a }
deriving (Functor, Applicative, Monad, MonadState s, MonadFail, MonadError String)
I needed to throwError when graph could not be built for some reason. Sadly I was thwarted because I don't see a way to get the computation result out of DotM. runDot needs to be exposed for this. Relatedly, execDot uses snd which discards the computation result. This caused me some confusion because the change that introduced ExceptT wasn't broken by my failure to handle the error.
This patch is enough to solve my problem. I had to copy a bit of code from makeGraph into my program.
--- a/Data/GraphViz/Types/Monadic.hs.orig 2021-10-06 15:03:47.523210031 -0700
+++ b/Data/GraphViz/Types/Monadic.hs 2021-10-06 15:04:04.472606433 -0700
@@ -52,7 +52,7 @@
-}
module Data.GraphViz.Types.Monadic
( Dot
- , DotM
+ , DotM(runDot)
, GraphID(..)
-- * Creating a generalised DotGraph.
, digraph
@@ -76,6 +76,8 @@
, edge
, (-->)
, (<->)
+ -- * Internals for monadic value extraction.
+ , convertStatements
) where
import Data.GraphViz.Attributes (Attributes)
I wanted to use
DotMto build up a transformer stack so I could do something like this:I needed to
throwErrorwhen graph could not be built for some reason. Sadly I was thwarted because I don't see a way to get the computation result out ofDotM. runDot needs to be exposed for this. Relatedly,execDotusessndwhich discards the computation result. This caused me some confusion because the change that introducedExceptTwasn't broken by my failure to handle the error.This patch is enough to solve my problem. I had to copy a bit of code from
makeGraphinto my program.