module Data.Exists (module Data.Exists.Internal) where
import Data.Exists.Internal
import Data.Exists.Defaults
import Prelude ((.), error)
import Unsafe.Coerce (unsafeCoerce)
import qualified Data.Traversable as T (foldMapDefault, fmapDefault)
import Data.Dynamic (toDyn, fromDyn)
import Control.Comonad (liftW)
import Control.Constraint.Combine (Empty)
import Data.Typeable (Typeable)
import Control.Exception (Exception)
import Data.Dynamic (Dynamic)
import GHC.Exts (Any)
import Data.Anything (Anything (..),
Anything1 (..))
import Control.Exception (SomeException (..))
import Prelude (Show (..),
Functor (..))
import Data.Foldable (Foldable (..))
import Data.Traversable (Traversable (..))
import Data.Functor.Contravariant (Contravariant (..))
import Data.Functor.Extend (Extend (..))
import Control.Comonad (Comonad (..))
import Control.Comonad.Env.Class (ComonadEnv (..))
import Control.Comonad.Traced.Class (ComonadTraced (..))
import Control.Comonad.Store.Class (ComonadStore (..))
import Data.Copointed (Copointed (..))
instance Existential Any where
type ConstraintOf Any = Empty
exists = unsafeCoerce
apply f a = f a
instance Existential1 Any where
type ConstraintOf1 Any = Empty
exists1 = unsafeCoerce
apply1 f a = f a
instance Existential Anything where
type ConstraintOf Anything = Empty
exists = Anything
apply f (Anything a) = f a
instance Existential1 Anything1 where
type ConstraintOf1 Anything1 = Empty
exists1 = Anything1
apply1 f (Anything1 a) = f a
instance Existential Dynamic where
type ConstraintOf Dynamic = Typeable
exists = toDyn
apply f d = f (fromDyn (error "this can't be happening!") d)
instance Existential SomeException where
type ConstraintOf SomeException = Exception
exists = SomeException
apply f (SomeException e) = f e
instance Show (Exists Show) where
show = showDefault
showsPrec = showsPrecDefault
instance Functor (Exists1 Functor) where
fmap = fmapDefault
instance Foldable (Exists1 Foldable) where
fold = foldDefault
foldMap = foldMapDefault
foldl = foldlDefault
foldr = foldrDefault
foldl1 = foldl1Default
foldr1 = foldr1Default
instance Functor (Exists1 Traversable) where
fmap = T.fmapDefault
instance Foldable (Exists1 Traversable) where
foldMap = T.foldMapDefault
instance Traversable (Exists1 Traversable) where
traverse = traverseDefault
sequenceA = sequenceADefault
mapM = mapMDefault
sequence = sequenceDefault
instance Contravariant (Exists1 Contravariant) where
contramap = contramapDefault
instance Functor (Exists1 Extend) where
fmap f = apply1 (exists1 . fmap f)
instance Extend (Exists1 Extend) where
duplicate = duplicateDefault
instance Functor (Exists1 Comonad) where
fmap = liftW
instance Extend (Exists1 Comonad) where
duplicate = apply1 (exists1 . fmap exists1 . duplicate)
instance Comonad (Exists1 Comonad) where
extract = extractDefault
instance Functor (Exists1 (ComonadEnv e)) where
fmap = liftW
instance Extend (Exists1 (ComonadEnv e)) where
duplicate = apply1 (exists1 . fmap exists1 . duplicate)
instance Comonad (Exists1 (ComonadEnv e)) where
extract = apply1 extract
instance ComonadEnv e (Exists1 (ComonadEnv e)) where
ask = askDefault
instance Functor (Exists1 (ComonadTraced m)) where
fmap = liftW
instance Extend (Exists1 (ComonadTraced m)) where
duplicate = apply1 (exists1 . fmap exists1 . duplicate)
instance Comonad (Exists1 (ComonadTraced m)) where
extract = apply1 extract
instance ComonadTraced m (Exists1 (ComonadTraced m)) where
trace = traceDefault
instance Functor (Exists1 (ComonadStore s)) where
fmap = liftW
instance Extend (Exists1 (ComonadStore s)) where
duplicate = apply1 (exists1 . fmap exists1 . duplicate)
instance Comonad (Exists1 (ComonadStore s)) where
extract = apply1 extract
instance ComonadStore s (Exists1 (ComonadStore s)) where
pos = posDefault
peek = peekDefault
peeks = peeksDefault
seek = seekDefault
seeks = seeksDefault
instance Copointed (Exists1 Copointed) where
copoint = copointDefault