Heterogeneous map
问题 I need a map which can contain arbitrary values as long as their types are of the same typeclass. My first naive approach was something like this: type HMap = forall a . MyClass a => M.Map Int a but it does not seem to work: the following code gives a compile error: testFunction :: (forall a . MyClass a => M.Map Int a) -> Int -> IO () testFunction m i = do case M.lookup i m of Nothing -> return () Just v -> someActionFromMyClass v >> putStrLn "OK" Ambiguous type variable `a0' in the