
8 Nov
2007
8 Nov
'07
8:57 a.m.
On Nov 7, 2007 4:34 PM, Nicholas Messenger
If you're willing to have an extra Typeable constraint, this does what you want:
import Data.Typeable (Typeable, cast) import Data.Maybe (fromMaybe)
toString :: (Show a, Typeable a) => a -> String toString x = fromMaybe (show x) (cast x)
Nice! Thank you for introducing me to the Typeable class (and by extension, Dynamic) -- I hadn't realized there was library support for dynamic types. G