import Data.Foldable (foldMap) import Data.Monoid (First(First, getFirst)) import Data.Maybe (fromMaybe) data Fruit = Fruit { color :: String, weight :: Int } theFruitIsRed :: Fruit -> Maybe String theFruitIsRed (Fruit "red" _) = Nothing theFruitIsRed _ = Just "Fruit not red" theFruitIsNotTooHeavy :: Fruit -> Maybe String theFruitIsNotTooHeavy (Fruit _ w) | w < 500 = Nothing | otherwise = Just "Too heavy" checkRules :: Fruit -> Maybe String checkRules = getFirst . foldMap (First .) [ theFruitIsRed , theFruitIsNotTooHeavy ] main = mapM (putStrLn . fromMaybe "No problems!" . checkRules) [ Fruit "red" 1000 , Fruit "red" 10 , Fruit "blue" 600 , Fruit "blue" 100 ]