
4 Oct
2012
4 Oct
'12
12:03 p.m.
On October 4, 2012 07:59:29 Ganesh Sittampalam wrote:
I have some nebulous concerns about abstraction violation, but since Typeable only lets you find out what the structure is, not actually take apart the contained data, it doesn't seem too much of a problem.
Ummm. Isn't that what cast (in Data.Typeable) does? cast :: (Typeable a, Typeable b) => a -> Maybe b For example, the following function import Data.Typeable import Data.Maybe magic :: Typeable a => a -> a magic x = case cast x of Just x -> cast $ fromJust $ x ++ " (ta da)" _ -> x gives you id except for strings. Cheers! -Tyson