From f557d5b954ceb5bb7048d0c0c2785716ddba733d Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 10 Jul 2025 00:13:57 +0100 Subject: [PATCH] Eta reduction --- src/Dodge/Item/Grammar.hs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Dodge/Item/Grammar.hs b/src/Dodge/Item/Grammar.hs index 3dd768060..5d5f026df 100644 --- a/src/Dodge/Item/Grammar.hs +++ b/src/Dodge/Item/Grammar.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE TupleSections #-} module Dodge.Item.Grammar ( invLDT, invLDT', @@ -152,8 +153,8 @@ itemToFunction itm = case itm ^. itType of CLICKER{} -> GadgetPlatformSF _ -> NoSF -structureToPotentialFunction :: LDTree ItemLink CItem -> S.Set ItemStructuralFunction -structureToPotentialFunction ldt = case ldt ^. ldtValue . _1 . itType of +treeToPotentialFunction :: LDTree ItemLink CItem -> S.Set ItemStructuralFunction +treeToPotentialFunction ldt = case ldt ^. ldtValue . _1 . itType of STICKYMOD -> S.singleton GrenadeHitEffectSF ATTACH GIMBAL -> S.singleton ProjectileStabiliserSF ATTACH GYROSCOPE -> S.singleton ProjectileStabiliserSF @@ -169,18 +170,16 @@ type LDTComb a b = LDTree b a -> LDTree b a -> Maybe (LDTree b a) leftIsParentCombine :: LDTComb CItem ItemLink leftIsParentCombine ltree rtree = do let l = rightChildList ltree - xs = dropWhile ((\s -> not $ S.member s (structureToPotentialFunction rtree)) . fst) l + xs = dropWhile ((\s -> not $ S.member s (treeToPotentialFunction rtree)) . fst) l (sf,linktype) <- safeHead xs - return $ - ltree & ldtRight .:~ (linktype, rtree & ldtValue . _2 .~ sf) + return $ ltree & ldtRight .:~ (linktype, rtree & ldtValue . _2 .~ sf) rightIsParentCombine :: LDTComb CItem ItemLink rightIsParentCombine ltree rtree = do let l = leftChildList rtree - xs = dropWhile ((\s -> not $ S.member s (structureToPotentialFunction ltree)) . fst) l + xs = dropWhile ((\s -> not $ S.member s (treeToPotentialFunction ltree)) . fst) l (sf,linktype) <- safeHead xs - return $ - rtree & ldtLeft .:~ (linktype, ltree & ldtValue . _2 .~ sf) + return $ rtree & ldtLeft .:~ (linktype, ltree & ldtValue . _2 .~ sf) leftChildList :: LDTree ItemLink CItem -> [(ItemStructuralFunction, ItemLink)] leftChildList t = foldl' f l (reverse $ t ^.. ldtLeft . each . _1) @@ -209,13 +208,20 @@ leftRightCombine f f' t1 t2 = f t1 t2 <|> checkdepth t1 t2 checktop t t' = f' t t' joinItemsInList :: (a -> a -> Maybe a) -> [a] -> [a] -joinItemsInList f xs = snd $ h (xs, []) +joinItemsInList f = fst . h . ([],) where - h ([], zs) = ([], zs) - h (y : ys, []) = h (ys, [y]) - h (y : ys, z : zs) = case f y z of - Nothing -> h (ys, y : z : zs) - Just w -> h (w : ys, zs) + h (zs, []) = (zs, []) + h ([],y : ys) = h ([y],ys) + h ( z : zs, y : ys) = case f y z of + Nothing -> h ( y : z : zs,ys) + Just w -> h ( zs,w : ys) +--joinItemsInList f xs = snd $ h (xs, []) +-- where +-- h ([], zs) = ([], zs) +-- h (y : ys, []) = h (ys, [y]) +-- h (y : ys, z : zs) = case f y z of +-- Nothing -> h (ys, y : z : zs) +-- Just w -> h (w : ys, zs) -- this puts the first elements in the intmap at the end of the list invLDT :: IM.IntMap Item -> [LDTree ItemLink CItem]