I'd need some help to design a monadic datatype, I seem to have trouble wrapping my head around the idea, but I pretty definitely know what I want. Only the type checker seems to require some persuading in that matter.
What I want is some datatype Primitive
that can be a monad. Functions of that are basically drawing primitives, and I want to be able to combine them and the combinations being primitives as well, much like the Parser
type in the library parsec
. But the actual drawing has to be done with an IO
monad.
Incidentally, I also have a class Drawable a
like this:
class Drawable a where
draw :: (MonadIO m) => Pos -> a -> m ()
And I want every Primitive of course to be drawable. Am thankful for any input.
I don't understand why you think this should be a monad. What's monadic about it?
You should design the API you want first, and incrementally think about how to abstract it.
Incidentally, Brent's diagrams library has a very nice compositional API that could provide some good ideas: http://byorgey.wordpress.com/2008/04/30/new-haskell-diagrams-library/