From 24a21e3807453312ee92ed68f977cd9523d49491 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Mon, 5 Jan 2026 15:19:18 +0000 Subject: [PATCH] Remove heterogenous list length function --- haskell/Main.hs | 2 +- haskell/Pre.hs | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/haskell/Main.hs b/haskell/Main.hs index 10b9142..136f0c2 100644 --- a/haskell/Main.hs +++ b/haskell/Main.hs @@ -47,7 +47,7 @@ main = mapHListF (\(Fanout (f, Op o)) -> (o &&& id) $ f input) parts in pure (input, rs, os) ) - $ ( flip map ([0 :: Int .. hlistfLength parts - 1]) $ + $ ( flip map ([0 :: Int .. foldHListF0 (const succ) 0 parts - 1]) $ \n@(show . succ -> nt) -> TestTree (mkTestName nt) diff --git a/haskell/Pre.hs b/haskell/Pre.hs index 60935c6..5ad7086 100644 --- a/haskell/Pre.hs +++ b/haskell/Pre.hs @@ -40,12 +40,10 @@ module Pre ( adjacentPairs, sortPair, HList (..), - hlistLength, HListF (..), foldHListF, foldHListF0, mapHListF, - hlistfLength, (/\), (/\\), nil, @@ -160,10 +158,6 @@ data HList (as :: List Type) :: Type where a -> HList as -> HList (a ': as) -hlistLength :: HList r -> Int -hlistLength = \case - HNil -> 0 - HCons _ l -> 1 + hlistLength l data HListF (f :: Type -> Type) (as :: List Type) :: Type where HNilF :: HListF f '[] @@ -181,10 +175,6 @@ foldHListF0 f e = \case HConsF x xs -> f x $ foldHListF0 f e xs mapHListF :: (forall a. f a -> g a) -> HListF f as -> HListF g as mapHListF t = foldHListF (\x r -> HConsF (t x) $ r) HNilF -hlistfLength :: HListF f r -> Int -hlistfLength = \case - HNilF -> 0 - HConsF _ l -> 1 + hlistfLength l newtype Fanout f g a = Fanout (f a, g a)