You thought you were adding something like this to your .ghci file:
instance (Show a) => Show (IORef a) where show a = show (unsafePerformIO (readIORef a))
This is unsafe, but if it is only for your personal use, perhaps this is normal.
For more general use, the previous answers work well for me. That is, either set the static message "I cannot show this":
instance Show (IORef a) where show _ = "<ioref>"
This will give something like:
> runFunc MyStruct <ioref> 4 "string val"
Or use a custom function. I suggest making a class and removing all instances of Show:
class ShowIO a where showIO :: a -> IO String instance Show a => ShowIO a where showIO = return . show instance ShowIO a => ShowIO (IORef a) where showIO a = readIORef a >>= showIO
Providing output (untested, this is only handwritten text):
> myFunc >>= showIO MyStruct "My String in an IORef" 4 "string val"
Thomas M. DuBuisson
source share