{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE InstanceSigs #-}
#if __GLASGOW_HASKELL__ >= 810
{-# LANGUAGE StandaloneKindSignatures #-}
#endif
module GHC.Generics.Generically (
Generically (..),
Generically1 (..),
) where
#if MIN_VERSION_base(4,17,0)
import GHC.Generics
#else
#if __GLASGOW_HASKELL__ >= 810
import Data.Kind (Type)
#endif
#if !MIN_VERSION_base(4,11,0)
import Data.Semigroup (Semigroup (..))
#endif
import GHC.Generics
import Control.Applicative (liftA2)
import Control.Applicative (Alternative (..))
import Data.Functor.Classes (Ord1 (..), Eq1 (..))
newtype Generically a = Generically a
instance (Generic a, Semigroup (Rep a ())) => Semigroup (Generically a) where
(<>) :: Generically a -> Generically a -> Generically a
Generically a
a <> :: Generically a -> Generically a -> Generically a
<> Generically a
b = a -> Generically a
forall a. a -> Generically a
Generically (Rep a () -> a
forall a x. Generic a => Rep a x -> a
to (a -> Rep a ()
forall a x. Generic a => a -> Rep a x
from a
a Rep a () -> Rep a () -> Rep a ()
forall a. Semigroup a => a -> a -> a
<> a -> Rep a ()
forall a x. Generic a => a -> Rep a x
from a
b :: Rep a ()))
instance (Generic a, Monoid (Rep a ())) => Monoid (Generically a) where
mempty :: Generically a
mempty :: Generically a
mempty = a -> Generically a
forall a. a -> Generically a
Generically (Rep a () -> a
forall a x. Generic a => Rep a x -> a
to (Rep a ()
forall a. Monoid a => a
mempty :: Rep a ()))
mappend :: Generically a -> Generically a -> Generically a
#if MIN_VERSION_base(4,11,0)
mappend :: Generically a -> Generically a -> Generically a
mappend = Generically a -> Generically a -> Generically a
forall a. Semigroup a => a -> a -> a
(<>)
#else
mappend (Generically a) (Generically b) = Generically (to (mappend (from a) (from b) :: Rep a ()))
#endif
#if __GLASGOW_HASKELL__ >= 810
type Generically1 :: forall k. (k -> Type) -> (k -> Type)
#endif
newtype Generically1 f a = Generically1 (f a)
instance (Generic1 f, Functor (Rep1 f)) => Functor (Generically1 f) where
fmap :: (a -> a') -> (Generically1 f a -> Generically1 f a')
fmap :: (a -> a') -> Generically1 f a -> Generically1 f a'
fmap a -> a'
f (Generically1 f a
as) = f a' -> Generically1 f a'
forall k (f :: k -> *) (a :: k). f a -> Generically1 f a
Generically1 (Rep1 f a' -> f a'
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 ((a -> a') -> Rep1 f a -> Rep1 f a'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a'
f (f a -> Rep1 f a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f a
as)))
(<$) :: a -> Generically1 f b -> Generically1 f a
a
a <$ :: a -> Generically1 f b -> Generically1 f a
<$ Generically1 f b
as = f a -> Generically1 f a
forall k (f :: k -> *) (a :: k). f a -> Generically1 f a
Generically1 (Rep1 f a -> f a
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 (a
a a -> Rep1 f b -> Rep1 f a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ f b -> Rep1 f b
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f b
as))
instance (Generic1 f, Applicative (Rep1 f)) => Applicative (Generically1 f) where
pure :: a -> Generically1 f a
pure :: a -> Generically1 f a
pure a
a = f a -> Generically1 f a
forall k (f :: k -> *) (a :: k). f a -> Generically1 f a
Generically1 (Rep1 f a -> f a
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 (a -> Rep1 f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a))
(<*>) :: Generically1 f (a -> b) -> Generically1 f a -> Generically1 f b
Generically1 f (a -> b)
fs <*> :: Generically1 f (a -> b) -> Generically1 f a -> Generically1 f b
<*> Generically1 f a
as = f b -> Generically1 f b
forall k (f :: k -> *) (a :: k). f a -> Generically1 f a
Generically1 (Rep1 f b -> f b
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 (f (a -> b) -> Rep1 f (a -> b)
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f (a -> b)
fs Rep1 f (a -> b) -> Rep1 f a -> Rep1 f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f a -> Rep1 f a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f a
as))
#if MIN_VERSION_base(4,10,0)
liftA2 :: (a -> b -> c) -> (Generically1 f a -> Generically1 f b -> Generically1 f c)
liftA2 :: (a -> b -> c)
-> Generically1 f a -> Generically1 f b -> Generically1 f c
liftA2 a -> b -> c
f (Generically1 f a
as) (Generically1 f b
bs) = f c -> Generically1 f c
forall k (f :: k -> *) (a :: k). f a -> Generically1 f a
Generically1 (Rep1 f c -> f c
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 ((a -> b -> c) -> Rep1 f a -> Rep1 f b -> Rep1 f c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> b -> c
f (f a -> Rep1 f a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f a
as) (f b -> Rep1 f b
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f b
bs)))
#endif
instance (Generic1 f, Alternative (Rep1 f)) => Alternative (Generically1 f) where
empty :: Generically1 f a
empty :: Generically1 f a
empty = f a -> Generically1 f a
forall k (f :: k -> *) (a :: k). f a -> Generically1 f a
Generically1 (Rep1 f a -> f a
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 Rep1 f a
forall (f :: * -> *) a. Alternative f => f a
empty)
(<|>) :: Generically1 f a -> Generically1 f a -> Generically1 f a
Generically1 f a
as1 <|> :: Generically1 f a -> Generically1 f a -> Generically1 f a
<|> Generically1 f a
as2 = f a -> Generically1 f a
forall k (f :: k -> *) (a :: k). f a -> Generically1 f a
Generically1 (Rep1 f a -> f a
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 (f a -> Rep1 f a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f a
as1 Rep1 f a -> Rep1 f a -> Rep1 f a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> f a -> Rep1 f a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f a
as2))
instance (Generic1 f, Eq1 (Rep1 f)) => Eq1 (Generically1 f) where
liftEq :: (a -> b -> Bool) -> (Generically1 f a -> Generically1 f b -> Bool)
liftEq :: (a -> b -> Bool) -> Generically1 f a -> Generically1 f b -> Bool
liftEq a -> b -> Bool
eq (Generically1 f a
as1) (Generically1 f b
as2) = (a -> b -> Bool) -> Rep1 f a -> Rep1 f b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq (f a -> Rep1 f a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f a
as1) (f b -> Rep1 f b
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f b
as2)
instance (Generic1 f, Ord1 (Rep1 f)) => Ord1 (Generically1 f) where
liftCompare :: (a -> b -> Ordering) -> (Generically1 f a -> Generically1 f b -> Ordering)
liftCompare :: (a -> b -> Ordering)
-> Generically1 f a -> Generically1 f b -> Ordering
liftCompare a -> b -> Ordering
cmp (Generically1 f a
as1) (Generically1 f b
as2) = (a -> b -> Ordering) -> Rep1 f a -> Rep1 f b -> Ordering
forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
cmp (f a -> Rep1 f a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f a
as1) (f b -> Rep1 f b
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 f b
as2)
#endif