This should indicate the right direction:
import Data.Typeable import Data.Dynamic import Control.Applicative readMay :: Read a => String -> Maybe a readMay s = case reads s of (a,[]):_ -> Just a _ -> Nothing reconstruct :: Typeable a => (Maybe a -> r) -> (String, String) -> r reconstruct k (typ,val) = case typ of "string" -> k $ cast =<< (readMay val :: Maybe String) "int" -> k $ cast =<< (readMay val :: Maybe Int) "double" -> k $ cast =<< (readMay val :: Maybe Double) reconstructToDyn (typ,val) = case typ of "string" -> toDyn <$> (readMay val :: Maybe String) "int" -> toDyn <$> (readMay val :: Maybe Int) "double" -> toDyn <$> (readMay val :: Maybe Double)
source share