Changes to Typeable

Tyson Whitehead twhitehead at gmail.com
Thu Oct 4 18:03:20 CEST 2012


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



More information about the Libraries mailing list