module Generics.MultiRec.CountIs where
import Generics.MultiRec
class CountIs (f :: (* -> *) -> * -> *) where
countIs :: f r ix -> Int
instance CountIs (I ix) where countIs _ = 1
instance CountIs (t :.: f) where countIs _ = 1
instance CountIs (K a) where countIs _ = 0
instance CountIs U where countIs _ = 0
instance (CountIs f) => CountIs (C c f) where
countIs (_ :: C c f r ix) = countIs (undefined :: f r ix)
instance (CountIs f) => CountIs (f :>: ix) where
countIs (_ :: (f :>: ix) r xi) = countIs (undefined :: f r ix)
instance (CountIs f, CountIs g) => CountIs (f :+: g) where
countIs (L x) = countIs x
countIs (R x) = countIs x
instance (CountIs f, CountIs g) => CountIs (f :*: g) where
countIs (_ :: (f :*: g) r ix) = countIs (undefined :: f r ix)
+ countIs (undefined :: g r ix)