From a487fd07dc72ba506b3d185c4d9317e5a443faa3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 17 Oct 2015 11:13:33 -0400 Subject: newtype info allows deriving monoid --- src/Propellor/Types/Info.hs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/Propellor/Types/Info.hs') diff --git a/src/Propellor/Types/Info.hs b/src/Propellor/Types/Info.hs index 347a03e7..3330a033 100644 --- a/src/Propellor/Types/Info.hs +++ b/src/Propellor/Types/Info.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-} module Propellor.Types.Info ( Info, @@ -17,15 +17,12 @@ import Data.Monoid import Data.Maybe -- | Information about a Host, which can be provided by its properties. -data Info = Info [(Dynamic, Bool)] +newtype Info = Info [(Dynamic, Bool)] + deriving (Monoid) instance Show Info where show (Info l) = "Info " ++ show (map (dynTypeRep . fst) l) -instance Monoid Info where - mempty = Info [] - mappend (Info a) (Info b) = Info (a <> b) - -- | Values stored in Info must be members of this class. -- -- This is used to avoid accidentially using other data types @@ -40,6 +37,7 @@ class (Typeable v, Monoid v) => IsInfo v where addInfo :: IsInfo v => Info -> v -> Info addInfo (Info l) v = Info ((toDyn v, propigateInfo v):l) +-- The list is reversed here because addInfo builds it up in reverse order. getInfo :: IsInfo v => Info -> v getInfo (Info l) = mconcat (mapMaybe (fromDynamic . fst) (reverse l)) -- cgit v1.2.3