{-# LANGUAGE
BangPatterns,
FlexibleContexts,
PolyKinds #-}
module Generic.Data.Internal.Utils where
import Data.Coerce
import GHC.Generics
gcoerce
:: (Generic a, Generic b, Coercible (Rep a) (Rep b))
=> a -> b
gcoerce = to . coerce1 . from
gcoerceBinop
:: (Generic a, Generic b, Coercible (Rep a) (Rep b))
=> (a -> a -> a) -> (b -> b -> b)
gcoerceBinop f x y = gcoerce (f (gcoerce x) (gcoerce y))
coerce' :: Coercible (f x) (g x) => f x -> g x
coerce' = coerce
coerce1 :: Coercible f g => f x -> g x
coerce1 = coerce
absurd1 :: V1 x -> a
absurd1 !_ = error "impossible"
from' :: Generic a => a -> Rep a ()
from' = from
to' :: Generic a => Rep a () -> a
to' = to
liftG2 :: Generic1 f => (Rep1 f a -> Rep1 f b -> Rep1 f c) -> f a -> f b -> f c
liftG2 = \(<?>) a b -> to1 (from1 a <?> from1 b)