What solutions are available if I apparently want to access to a hidden
data constructor?
I'm using a package that carries around things in a convenient ReaderT
monad. Their runReaderT/unwrapping function is in a hidden module. I'd
like to be able to unwrap it arbitrariy/manually with an arbitrary
environment. So I don't have any qualms with doing it manually -- however,
the environment type has a hidden data constructor, so I can't generate an
environment that will typecheck with runReaderT.
Is there any way I can get around this? Or should I give this up as
impossible and attempt to restructure my program? I'm planning on
deploying this project to a remote system with an automated build system
so I'm not sure if I want to edit the source of the package directly/fork
it.
In specific, I'm using scotty, and I'm trying to emulate runActionM from
the Web.Scotty.Action module. I trying to emulate a page request and
capture the results, and also to emulate a page request that normally has
IO side effects.
Specific example:
-- LibraryPackage.hs
module LibraryPackage (SpecialReader) where
import Control.Monad.Reader
type SpecialReader a = Reader Env a
data Env = Env Int
runSpecialReader r = runReader r (Env 5)
-- Main.hs
import LibraryPackage
main = do
let
r = return 10 :: SpecialReader Int
-- problem here -- cannot construct an `Env`
print $ runReader r (Env 5)
No comments:
Post a Comment