Hello,
To analyse, test, and debug my system I use a WriterT for logging. The
log file created can be quite large and a lot of 'Log' is created in
memory, too.
I thought, that maybe I can (ab)use the compiler to switch logging on
and off as needed before compiling. I tried to either always return an
empty Log when running the WriterT, or just always ignore logging
depending on a constant and hoped GHC to optimize the logging away.
_NOLOGGING = True
runWT :: (Monad m) => (WriterT Log m a) -> m (a, Log)
runWT m
| _NOLOGGING = runWriterT m empty >>= \(a,_) -> return (a,emptyLog )
| otherwise = runWriterT m emptyLog
logging :: Message -> WriterT Log m ()
logging msg = if _NOLOGGING then return () else tell msg
However, according to the heap profile there is still a lot of 'Log' in
the memory. So, is this possible this way at all and if not, is there
another (apart from removing all logging by hand).
Thanks