diff options
Diffstat (limited to 'src/Data/Dependent/EnumMap/Strict/Unsafe.hs')
-rw-r--r-- | src/Data/Dependent/EnumMap/Strict/Unsafe.hs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Data/Dependent/EnumMap/Strict/Unsafe.hs b/src/Data/Dependent/EnumMap/Strict/Unsafe.hs new file mode 100644 index 0000000..4d4a9eb --- /dev/null +++ b/src/Data/Dependent/EnumMap/Strict/Unsafe.hs @@ -0,0 +1,44 @@ +{-| +These are variants of the functions in "Data.Dependent.EnumMap.Strict" that do +not type-check keys: they do not check that you don't create two keys with the +same 'Int' and different types. As a result, these functions do not have a +'Data.Type.Equality.TestEquality' constraint, and are faster. + +Be aware though, because one can easily create @unsafeCoerce@ with this API: + +@ +{-# LANGUAGE ScopedTypeVariables TypeFamilies #-} + +import qualified Data.Dependent.EnumMap.Strict as DE +import qualified Data.Dependent.EnumMap.Strict.Unsafe as DEU + +import Data.Functor.Identity +import Data.Maybe +import Data.Some + +data Foo a = Foo Int + deriving (Show) + +instance DE.Enum1 Foo where + type Enum1Info Foo = () + fromEnum1 (Foo i) = (i, ()) + toEnum1 i () = Some (Foo i) + +unsafe :: forall a b. a -> b +unsafe x = runIdentity $ fromJust $ + DEU.lookupUnsafe (Foo 1 :: Foo b) $ + DE.singleton (Foo 1 :: Foo a) (Identity x) +@ + +-} +module Data.Dependent.EnumMap.Strict.Unsafe ( + adjustUnsafe, + alterUnsafe, + lookupUnsafe, + findWithDefaultUnsafe, + unionUnsafe, + unionWithUnsafe, +) where + +import Prelude () +import Data.Dependent.EnumMap.Strict.Internal |