, HFoldrable(..)
, HConcatable(..)
, HMappable(..)
+
+ , HLength(..)
)
where
import Data.Typeable
+import Types.Data.Num hiding ((:*:))
-- HList
) => HMappable f (HCons x xs) where
type HMap f (HCons x xs) = HCons (Apply f x) (HMap f xs)
hMap f (HCons x xs) = hCons (apply f x) (hMap f xs)
+
+-- HLength
+class IntegerT (HLengthOf l) => HLength l where
+ type HLengthOf l
+ hLength :: Integral n => l -> n
+
+instance HLength HNil where
+ type HLengthOf HNil = D0
+ hLength _ = 0
+
+instance ( HLength l
+ , IntegerT (Succ (HLengthOf l))
+ ) => HLength (HCons e l) where
+ type HLengthOf (HCons e l) = Succ (HLengthOf l)
+ hLength (HCons _ l) = 1 + hLength l