1{-# LANGUAGE ExplicitForAll #-}
2{-# LANGUAGE ScopedTypeVariables #-}
12import Prelude hiding (lookup)
14import Data.Proxy (Proxy (..))
15import Data.Typeable (TypeRep, Typeable, typeOf, typeRep)
17import Unsafe.Coerce (unsafeCoerce)
19import qualified Data.Map.Lazy as LMap
21-- | Map-like data structure with types served as the keys.
22newtype TypeRepMap = TypeRepMap
23 { unMap :: LMap.Map TypeRep Any
28empty = TypeRepMap mempty
30-- | Inserts the value with its type as a key.
31insert :: Typeable a => a -> TypeRepMap -> TypeRepMap
32insert val = TypeRepMap . LMap.insert (typeOf val) (unsafeCoerce val) . unMap
34-- | Looks up the value at the type.
35-- >>> let x = lookup $ insert (11 :: Int) empty
40lookup :: forall a . Typeable a => TypeRepMap -> Maybe a
41lookup = fmap unsafeCoerce . LMap.lookup (typeRep (Proxy :: Proxy a)) . unMap
43size :: TypeRepMap -> Int
44size = LMap.size . 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