diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-10-17 11:13:33 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-10-17 11:13:33 -0400 |
| commit | a487fd07dc72ba506b3d185c4d9317e5a443faa3 (patch) | |
| tree | 8f164d1c6fe86e03dc1ef6c26a6f377725add7e5 /src | |
| parent | 02269cc630fd8bf81423eb6c0d9d6442b0661847 (diff) | |
newtype info allows deriving monoid
Diffstat (limited to 'src')
| -rw-r--r-- | src/Propellor/Types/Info.hs | 10 |
1 files changed, 4 insertions, 6 deletions
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)) |
