diff --git a/haskell/Main.hs b/haskell/Main.hs index 69175d2..c61db06 100644 --- a/haskell/Main.hs +++ b/haskell/Main.hs @@ -41,7 +41,7 @@ main = describe pt do input <- liftIO $ parseFile $ "../inputs/" <> t <> "/" <> pt let (rs, os) = - ((getConst . foldHListF (\x r -> Const $ fst x : getConst r) (Const [])) &&& foldHListF (HCons . snd) HNil) $ + (foldHListF0 ((:) . fst) [] &&& foldHListF (HCons . snd) HNil) $ mapHListF (\(Fanout (f, Op o)) -> (o &&& id) $ f input) parts for_ (zip [1 :: Int ..] rs) $ uncurry $ \(show -> n) -> it n . pureGoldenTextFile ("../outputs/" <> t <> "/" <> pt <> "/" <> n) . (<> "\n") diff --git a/haskell/Pre.hs b/haskell/Pre.hs index bbbf6c5..f087d17 100644 --- a/haskell/Pre.hs +++ b/haskell/Pre.hs @@ -43,6 +43,7 @@ module Pre ( sortPair, HListF (..), foldHListF, + foldHListF0, mapHListF, (/\), (/\\), @@ -150,6 +151,10 @@ foldHListF :: (forall x xs. f x -> r xs -> r (x ': xs)) -> r '[] -> HListF f as foldHListF f e = \case HNilF -> e HConsF x xs -> f x $ foldHListF f e xs +foldHListF0 :: (forall x. f x -> r -> r) -> r -> HListF f as -> r +foldHListF0 f e = \case + HNilF -> e + 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