summaryrefslogtreecommitdiff
path: root/src/Propellor/PropAccum.hs
diff options
context:
space:
mode:
authorJoey Hess2015-01-24 22:38:10 -0400
committerJoey Hess2015-01-24 22:38:51 -0400
commit0ee04ecc43e047b00437fb660e71f7dd67dd3afc (patch)
tree621e0ebc68a2afb9410ce6f368bec865f31cc507 /src/Propellor/PropAccum.hs
parent141a7c028bba8d5b9743f2ab1397e69c313a523c (diff)
GADT properties seem to work (untested)
* Property has been converted to a GADT, and will be Property NoInfo or Property HasInfo. This was done to make sure that ensureProperty is only used on properties that do not have Info. Transition guide: - Change all "Property" to "Property NoInfo" or "Property WithInfo" (The compiler can tell you if you got it wrong!) - To construct a RevertableProperty, it is useful to use the new (<!>) operator - Constructing a list of properties can be problimatic, since Property NoInto and Property WithInfo are different types and cannot appear in the same list. To deal with this, "props" has been added, and can built up a list of properties of different types, using the same (&) and (!) operators that are used to build up a host's properties.
Diffstat (limited to 'src/Propellor/PropAccum.hs')
-rw-r--r--src/Propellor/PropAccum.hs33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/Propellor/PropAccum.hs b/src/Propellor/PropAccum.hs
index ddbc1e66..139f1471 100644
--- a/src/Propellor/PropAccum.hs
+++ b/src/Propellor/PropAccum.hs
@@ -16,6 +16,15 @@ import Propellor.Property
host :: HostName -> Host
host hn = Host hn [] mempty
+-- | Starts accumulating a list of properties.
+--
+-- > propertyList "foo" $ props
+-- > & someproperty
+-- > ! oldproperty
+-- > & otherproperty
+props :: PropList
+props = PropList []
+
-- | Something that can accumulate properties.
class PropAccum h where
-- | Adds a property.
@@ -23,13 +32,10 @@ class PropAccum h where
-- Can add Properties and RevertableProperties
(&) :: IsProp p => h -> p -> h
- -- | Like (&), but adds the property as the
- -- first property of the host. Normally, property
- -- order should not matter, but this is useful
- -- when it does.
+ -- | Like (&), but adds the property at the front of the list.
(&^) :: IsProp p => h -> p -> h
- getProperties :: h -> [Property]
+ getProperties :: h -> [Property HasInfo]
instance PropAccum Host where
(Host hn ps is) & p = Host hn (ps ++ [toProp p])
@@ -38,6 +44,13 @@ instance PropAccum Host where
(getInfoRecursive p <> is)
getProperties = hostProperties
+data PropList = PropList [Property HasInfo]
+
+instance PropAccum PropList where
+ PropList l & p = PropList (l ++ [toProp p])
+ PropList l &^ p = PropList ([toProp p] ++ l)
+ getProperties (PropList l) = l
+
-- | Adds a property in reverted form.
(!) :: PropAccum h => h -> RevertableProperty -> h
h ! p = h & revert p
@@ -57,8 +70,12 @@ infixl 1 !
--
-- PrivData Info is propigated, so that properties used inside a
-- PropAccum will have the necessary PrivData available.
-propigateContainer :: PropAccum container => container -> Property -> Property
-propigateContainer c prop = mkProperty
+propigateContainer
+ :: (PropAccum container)
+ => container
+ -> Property HasInfo
+ -> Property HasInfo
+propigateContainer c prop = infoProperty
(propertyDesc prop)
(propertySatisfy prop)
(propertyInfo prop)
@@ -72,4 +89,4 @@ propigateContainer c prop = mkProperty
, _privData = _privData i
}
cs = map go (propertyChildren p)
- in mkProperty (propertyDesc p) (propertySatisfy p) i' cs
+ in infoProperty (propertyDesc p) (propertySatisfy p) i' cs