X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=hs-rrdtool.git;a=blobdiff_plain;f=Data%2FHList%2FPrelude.hs;fp=Data%2FHList%2FPrelude.hs;h=3ab596ffb1e45c2aacf9484384b5f9334e454f81;hp=3eb7e81cc37e80809878498b610dc86ee15b772a;hb=a584a7c4d5ff7e6651f41070b0d2d5032d49b0dd;hpb=4611522487b382b839a53e75e3feb2aac8764074 diff --git a/Data/HList/Prelude.hs b/Data/HList/Prelude.hs index 3eb7e81..3ab596f 100644 --- a/Data/HList/Prelude.hs +++ b/Data/HList/Prelude.hs @@ -27,10 +27,13 @@ module Data.HList.Prelude , HFoldrable(..) , HConcatable(..) , HMappable(..) + + , HLength(..) ) where import Data.Typeable +import Types.Data.Num hiding ((:*:)) -- HList @@ -153,3 +156,18 @@ instance ( Applyable f x ) => 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