From 27aa7351340045b2aaf7d7447cbf711c793cf654 Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Tue, 28 Apr 2020 12:56:50 +0200 Subject: [PATCH] add GEq instnaces for IORef and STRef --- some.cabal | 1 + src/Data/GADT/Instances.hs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/Data/GADT/Instances.hs diff --git a/some.cabal b/some.cabal index 8dc21de..d46079f 100644 --- a/some.cabal +++ b/some.cabal @@ -63,6 +63,7 @@ library exposed-modules: Data.GADT.Compare Data.GADT.DeepSeq + Data.GADT.Instances Data.GADT.Show Data.Some Data.Some.Church diff --git a/src/Data/GADT/Instances.hs b/src/Data/GADT/Instances.hs new file mode 100644 index 0000000..1fa358e --- /dev/null +++ b/src/Data/GADT/Instances.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE CPP #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Data.GADT.Instances where + +import Data.IORef (IORef) +import Data.STRef (STRef) +import Unsafe.Coerce (unsafeCoerce) + +import Data.GADT.Compare (GEq(..)) + +#if __GLASGOW_HASKELL__ >=708 +import Data.Typeable ((:~:)( Refl )) +#endif + +instance GEq IORef where + a `geq` b = if a == unsafeCoerce b then Just $ unsafeCoerce Refl else Nothing + +instance GEq (STRef s) where + a `geq` b = if a == unsafeCoerce b then Just $ unsafeCoerce Refl else Nothing +