{-# LANGUAGE CPP, FlexibleContexts, FlexibleInstances, TypeOperators #-}
#if __GLASGOW_HASKELL__ < 710
{-# LANGUAGE OverlappingInstances #-}
#endif
module Test.LeanCheck.Generic
( genericList
, genericTiers
)
where
import GHC.Generics
import Test.LeanCheck.Core
genericList :: (Generic a, Listable' (Rep a)) => [a]
genericList = concat genericTiers
genericTiers :: (Generic a, Listable' (Rep a)) => [[a]]
genericTiers = mapT to tiers'
class Listable' f where
tiers' :: [[f p]]
instance Listable' V1 where
tiers' = undefined
instance Listable' U1 where
tiers' = [[U1]]
instance Listable c => Listable' (K1 i c) where
tiers' = mapT K1 tiers
instance (Listable' a, Listable' b) => Listable' (a :+: b) where
tiers' = mapT L1 tiers' \/ mapT R1 tiers'
instance (Listable' a, Listable' b) => Listable' (a :*: b) where
tiers' = productWith (:*:) tiers' tiers'
instance Listable' f => Listable' (S1 c f) where
tiers' = mapT M1 tiers'
instance Listable' f => Listable' (D1 c f) where
tiers' = mapT M1 tiers'
#if __GLASGOW_HASKELL__ >= 710
instance {-# OVERLAPPING #-} Listable' (C1 c U1) where
tiers' = mapT M1 tiers'
instance {-# OVERLAPPABLE #-} Listable' f => Listable' (C1 c f) where
tiers' = delay $ mapT M1 tiers'
#else
instance Listable' (C1 c U1)
where tiers' = mapT M1 tiers'
instance Listable' f => Listable' (C1 c f)
where tiers' = delay $ mapT M1 tiers'
#endif