{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
#if __GLASGOW_HASKELL__ >=704
{-# LANGUAGE Safe #-}
#elif __GLASGOW_HASKELL__ >=702
{-# LANGUAGE Trustworthy #-}
#endif
module Data.Universe.Generic where
import GHC.Generics
import Data.Universe.Class
import Data.Universe.Helpers
class GUniverse f where
guniverse :: [f a]
instance GUniverseSum f => GUniverse (M1 i c f) where
guniverse :: forall a. [M1 i c f a]
guniverse = forall a b. (a -> b) -> [a] -> [b]
map forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall a b. (a -> b) -> a -> b
$ forall a. [[a]] -> [a]
interleave forall (f :: * -> *) a. GUniverseSum f => [[f a]]
guniverseSum
class GUniverseSum f where
guniverseSum :: [[f a]]
instance GUniverseSum V1 where
guniverseSum :: forall a. [[V1 a]]
guniverseSum = []
instance (GUniverseSum f, GUniverseSum g) => GUniverseSum (f :+: g) where
guniverseSum :: forall a. [[(:+:) f g a]]
guniverseSum = forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> [a] -> [b]
map forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1) forall (f :: * -> *) a. GUniverseSum f => [[f a]]
guniverseSum forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> [a] -> [b]
map forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1) forall (f :: * -> *) a. GUniverseSum f => [[f a]]
guniverseSum
instance GUniverseProduct f => GUniverseSum (M1 i c f) where
guniverseSum :: forall a. [[M1 i c f a]]
guniverseSum = [forall a b. (a -> b) -> [a] -> [b]
map forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall (f :: * -> *) a. GUniverseProduct f => [f a]
guniverseProduct]
class GUniverseProduct f where
guniverseProduct :: [f a]
instance GUniverseProduct U1 where
guniverseProduct :: forall a. [U1 a]
guniverseProduct = [forall k (p :: k). U1 p
U1]
instance (GUniverseProduct f, GUniverseProduct g) => GUniverseProduct (f :*: g) where
guniverseProduct :: forall a. [(:*:) f g a]
guniverseProduct = forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
cartesianProduct forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) forall (f :: * -> *) a. GUniverseProduct f => [f a]
guniverseProduct forall (f :: * -> *) a. GUniverseProduct f => [f a]
guniverseProduct
instance GUniverseProduct f => GUniverseProduct (M1 i c f) where
guniverseProduct :: forall a. [M1 i c f a]
guniverseProduct = forall a b. (a -> b) -> [a] -> [b]
map forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall (f :: * -> *) a. GUniverseProduct f => [f a]
guniverseProduct
instance Universe a => GUniverseProduct (K1 r a) where
guniverseProduct :: forall a. [K1 r a a]
guniverseProduct = forall a b. (a -> b) -> [a] -> [b]
map forall k i c (p :: k). c -> K1 i c p
K1 forall a. Universe a => [a]
universe
universeGeneric :: (Generic a, GUniverse (Rep a)) => [a]
universeGeneric :: forall a. (Generic a, GUniverse (Rep a)) => [a]
universeGeneric = forall a b. (a -> b) -> [a] -> [b]
map forall a x. Generic a => Rep a x -> a
to forall (f :: * -> *) a. GUniverse f => [f a]
guniverse
#if __GLASGOW_HASKELL__ >= 804
#endif