{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DataKinds #-}
module Propellor.PropAccum
( host
, Props(..)
, props
, (&)
, (&^)
, (!)
) where
import Propellor.Types
import Propellor.Types.MetaTypes
import Propellor.Types.Core
import Propellor.Property
import GHC.TypeLits
import Data.Monoid
import Prelude
host :: HostName -> Props metatypes -> Host
host :: forall metatypes. HostName -> Props metatypes -> Host
host HostName
hn (Props [ChildProperty]
ps) = HostName -> [ChildProperty] -> Info -> Host
Host HostName
hn [ChildProperty]
ps (forall a. Monoid a => [a] -> a
mconcat (forall a b. (a -> b) -> [a] -> [b]
map forall p. IsProp p => p -> Info
getInfoRecursive [ChildProperty]
ps))
props :: Props UnixLike
props :: Props UnixLike
props = forall metatypes. [ChildProperty] -> Props metatypes
Props []
infixl 1 &
infixl 1 &^
infixl 1 !
type family GetMetaTypes x where
GetMetaTypes (Property (MetaTypes t)) = MetaTypes t
GetMetaTypes (RevertableProperty (MetaTypes t) undo) = MetaTypes t
type family NoteFor symbol :: ErrorMessage where
NoteFor symbol =
'Text "Probably the problem is with the last property added with "
':<>: symbol
':<>: 'Text " in the code excerpt below."
(&)
::
( IsProp p
, MetaTypes y ~ GetMetaTypes p
, CheckCombinableNote x y (NoteFor ('Text "&"))
)
=> Props (MetaTypes x)
-> p
-> Props (MetaTypes (Combine x y))
Props [ChildProperty]
c & :: forall {a} p (y :: [a]) (x :: [a]).
(IsProp p, MetaTypes y ~ GetMetaTypes p,
CheckCombinableNote x y (NoteFor ('Text "&"))) =>
Props (MetaTypes x) -> p -> Props (MetaTypes (Combine x y))
& p
p = forall metatypes. [ChildProperty] -> Props metatypes
Props ([ChildProperty]
c forall a. [a] -> [a] -> [a]
++ [forall p. IsProp p => p -> ChildProperty
toChildProperty p
p])
(&^)
::
( IsProp p
, MetaTypes y ~ GetMetaTypes p
, CheckCombinableNote x y (NoteFor ('Text "&^"))
)
=> Props (MetaTypes x)
-> p
-> Props (MetaTypes (Combine x y))
Props [ChildProperty]
c &^ :: forall {a} p (y :: [a]) (x :: [a]).
(IsProp p, MetaTypes y ~ GetMetaTypes p,
CheckCombinableNote x y (NoteFor ('Text "&^"))) =>
Props (MetaTypes x) -> p -> Props (MetaTypes (Combine x y))
&^ p
p = forall metatypes. [ChildProperty] -> Props metatypes
Props (forall p. IsProp p => p -> ChildProperty
toChildProperty p
p forall a. a -> [a] -> [a]
: [ChildProperty]
c)
(!)
:: CheckCombinableNote x z (NoteFor ('Text "!"))
=> Props (MetaTypes x)
-> RevertableProperty (MetaTypes y) (MetaTypes z)
-> Props (MetaTypes (Combine x z))
Props [ChildProperty]
c ! :: forall {a} {k} (x :: [a]) (z :: [a]) (y :: k).
CheckCombinableNote x z (NoteFor ('Text "!")) =>
Props (MetaTypes x)
-> RevertableProperty (MetaTypes y) (MetaTypes z)
-> Props (MetaTypes (Combine x z))
! RevertableProperty (MetaTypes y) (MetaTypes z)
p = forall metatypes. [ChildProperty] -> Props metatypes
Props ([ChildProperty]
c forall a. [a] -> [a] -> [a]
++ [forall p. IsProp p => p -> ChildProperty
toChildProperty (forall setup undo.
RevertableProperty setup undo -> RevertableProperty undo setup
revert RevertableProperty (MetaTypes y) (MetaTypes z)
p)])