1{-# LANGUAGE ExplicitForAll #-}
2{-# LANGUAGE ScopedTypeVariables #-}
13import Prelude hiding (lookup)
15import Data.Proxy (Proxy (..))
16import Data.Typeable (TypeRep, Typeable, typeOf, typeRep)
18import Unsafe.Coerce (unsafeCoerce)
20import qualified Data.Map.Lazy as LMap
22-- | Map-like data structure with types served as the keys.
23newtype TypeRepMap = TypeRepMap
24 { unMap :: LMap.Map TypeRep Any
29empty = TypeRepMap mempty
31-- | Inserts the value with its type as a key.
32insert :: Typeable a => a -> TypeRepMap -> TypeRepMap
33insert val = TypeRepMap . LMap.insert (typeOf val) (unsafeCoerce val) . unMap
35-- | Looks up the value at the type.
36-- >>> let x = lookup $ insert (11 :: Int) empty
41lookup :: forall a . Typeable a => TypeRepMap -> Maybe a
42lookup = fmap unsafeCoerce . LMap.lookup (typeRep (Proxy :: Proxy a)) . unMap
44size :: TypeRepMap -> Int
45size = LMap.size . unMap
47dbgShowTree :: TypeRepMap -> String
48dbgShowTree = LMap.showTreeWith (\k _ -> show k) False True . unMap
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list