Skip to content

Commit

Permalink
Add type role for safe coercion
Browse files Browse the repository at this point in the history
Coercing in the value type parameter is possible:
(coerce (empty :: HashMap Int (Additive Int))) :: HashMap Int Int

But coercing in the key parameter is forbidden, because the two types
might have different Hashable implementations.
  • Loading branch information
fehrenbach committed Mar 20, 2021
1 parent ad7bf9f commit 47b511e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Data/HashMap.purs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import Partial.Unsafe (unsafePartial)
-- | Note that this is an *unordered* collection.
foreign import data HashMap :: Type -> Type -> Type

type role HashMap nominal representational

foreign import eqPurs :: forall k v. Fn2 (k -> k -> Boolean) (v -> v -> Boolean) (HashMap k v -> HashMap k v -> Boolean)

instance eqHashMap :: (Eq k, Eq v) => Eq (HashMap k v) where
Expand Down

0 comments on commit 47b511e

Please sign in to comment.