Skip to content

add GEq instnaces for IORef and STRef #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions some.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ library
exposed-modules:
Data.GADT.Compare
Data.GADT.DeepSeq
Data.GADT.Instances
Data.GADT.Show
Data.Some
Data.Some.Church
Expand Down
21 changes: 21 additions & 0 deletions src/Data/GADT/Instances.hs
Original file line number Diff line number Diff line change
@@ -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