diff options
| author | Joey Hess <joeyh@joeyh.name> | 2016-03-17 11:26:35 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2016-03-17 11:58:24 -0400 |
| commit | 86f3373dc429bd16f0153787eaa45049e44c6bb0 (patch) | |
| tree | 27abb1e615d2df49e68576f661b0d3acc9b74bb8 /src | |
| parent | 70b77dd31c4538361a844ef049bed9ad2f273a3b (diff) | |
let's not try to get outertarget from monad
To get outertarget from the Propellor monad, the monad would have to be
parameteriszed with an outertarget type, since there's no single type.
For example:
newtype Propellor target p = Propellor { runWithHost :: RWST target () () IO p }
deriving (Monad, Applicative, Functor)
But then mkProperty becomes a problem, since the Propellor action
passed to it needs to already be of UnixLike type:
mkProperty :: Propellor UnixLike () -> Property UnixLike
mkProperty a = Property unixLike a
Could maybe live with that, but then `target` type check fails:
Expected type: Propellor (Targeting combinedtarget) ()
Actual type: Propellor (Targeting oldtarget) ()
Problem being that it's reusing the `a` which is a Propellor target ()
target newtarget (Property oldtarget a) = Property (intersectTarget oldtarget newtarget) a
And, the new Property has a different target, so it can't use the old `a`.
So, I'd need a way to cast one Propellor target () to a different target.
Maybe:
target newtarget (Property oldtarget (Propellor a)) =
let combinedtarget = intersectTarget oldtarget newtarget
in Property combinedtarget (Propellor (unsafeCoerce a))
But is that safe??
Even if it is, I can't see how to make ensureProperty get the outertarget
type. It returns Propellor (Targeting outertarget) (), which can read
the target from the RWST monad, but how to use that where the type of the
function is defined?
Rather than all that complication, it doesn't seem too bad to
require outertarget be passed to ensureProperty.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Propellor/Types/Target.hs | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/Propellor/Types/Target.hs b/src/Propellor/Types/Target.hs index 4d80f35c..40b3891e 100644 --- a/src/Propellor/Types/Target.hs +++ b/src/Propellor/Types/Target.hs @@ -104,15 +104,13 @@ freeBSD = targeting OSFreeBSD targeting :: Target -> Targeting os targeting o = Targeting [o] --- Demo. The outeros parameter would come from the Propellor monad in real --- life. --- XXX Can type inference work if outeros comes from Propellor monad? +-- The outertarget parameter needs to be passed in from the outer property. ensureProperty :: ((innertarget `NotSupersetTargets` outertarget) ~ CanCombineTargets) => Targeting outertarget -> Property (Targeting innertarget) -> IO () -ensureProperty outeros (Property inneros a) = a +ensureProperty outertarget (Property inneros a) = a -- | The union of two lists of Targets. unionTargets |
