From d68a8790ce04b5a3d88f1f10d912e3adefb578f3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 10 Sep 2017 19:55:08 +0100 Subject: [PATCH] Define maxBoundMetavariable using a helper. --- src/Diff.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Diff.hs b/src/Diff.hs index d4dbab4e3..a91015c25 100644 --- a/src/Diff.hs +++ b/src/Diff.hs @@ -54,9 +54,12 @@ freeMetavariables = cata $ \ diff -> case diff of maxBoundMetavariable :: (Foldable syntax, Functor syntax) => Diff syntax ann -> Maybe Metavar maxBoundMetavariable = cata $ \ diff -> case diff of - Copy bindings _ -> foldr (max . Just . fst) Nothing bindings + Copy bindings _ -> foldMaxMap (Just . fst) bindings Var _ -> Nothing - Patch patch -> foldr (max . foldr max Nothing) Nothing patch + Patch patch -> foldMaxMap (foldMaxMap id) patch + +foldMaxMap :: (Foldable t, Ord b) => (a -> Maybe b) -> t a -> Maybe b +foldMaxMap f = foldr (max . f) Nothing newtype Env a = Env { unEnv :: [(Metavar, a)] }