]> hydra-www.ietfng.org Git - dyna2/commitdiff
Add hrllen to HList utilities module
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Thu, 29 Nov 2012 07:10:58 +0000 (02:10 -0500)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Thu, 29 Nov 2012 07:10:58 +0000 (02:10 -0500)
src/Dyna/XXX/HList.hs

index 8eecd93a48e9ce095301a97b817c1974b50c3819..83bc6e22599efeb1bddeb580f26fb514c81d6408 100644 (file)
@@ -25,7 +25,7 @@ module Dyna.XXX.HList(
   HList(..), hlmapa,
 
   -- * HLists of a type constructor's images
-  HRList(..), hrlmapa, hrlmap, hrlproj, hrlTravProj,
+  HRList(..), hrlmapa, hrllen, hrlmap, hrlproj, hrlTravProj,
 
   -- * Interoperation between HList and HRList
   HLR(..), hlToHrl,
@@ -87,6 +87,13 @@ instance Show (HRList r '[]) where show _ = "HRN"
 instance (Show (r a), Show (HRList r as)) => Show (HRList r (a ': as)) where
     show (a :++ as) = show a ++ " :+ " ++ show as
 
+hrllen :: HRList r t -> Int
+hrllen = go 0
+ where
+  go :: Int -> HRList r t -> Int
+  go a HRN = a
+  go a (x :++ xs) = a `seq` go (a+1) xs
+
 -- | Shift the type-function of a HRList
 hrlmap :: (forall a . r a -> s a) -> HRList r t -> HRList s t
 hrlmap _  HRN       = HRN