This commit is contained in:
Joey Hess 2014-12-07 20:31:22 -04:00
parent ac0bedb90b
commit 27d00296ec
1 changed files with 19 additions and 7 deletions

View File

@ -12,6 +12,7 @@ This works, but it's error-prone. Consider this example:
Here, the Info of `foo` is not propigated out. Nor is `bar`'s Info. Of Here, the Info of `foo` is not propigated out. Nor is `bar`'s Info. Of
course, only one of them will be run, and only its info should be course, only one of them will be run, and only its info should be
propigated out.. propigated out..
---- ----
Currently, ensureProperty detects if it's called on a property with a Currently, ensureProperty detects if it's called on a property with a
@ -73,8 +74,7 @@ that has no Info. Only allow calling ensureProperty on this new type.
(Or, remove propertyInfo from Property, and add a new InfoProperty that (Or, remove propertyInfo from Property, and add a new InfoProperty that
has the info.) has the info.)
This would surely work, but it adds a lot of complexity to property But, propertyList can only contain one type at a time,
combiators. Also, propertyList could only contain one type at a time,
not a mixed list of Property and SimpleProperty. not a mixed list of Property and SimpleProperty.
Could a GADT be used instead? Could a GADT be used instead?
@ -85,9 +85,21 @@ Could a GADT be used instead?
data HasInfo data HasInfo
data NoInfo data NoInfo
data Property i where data Property = IProperty (GProperty HasInfo) | SProperty (GProperty NoInfo)
InfoProperty :: Desc -> Propellor Result -> Info -> Property HasInfo
SimpleProperty :: Desc -> Propellor Result -> Property NoInfo
ensureProperty :: Property NoInfo -> Propellor Result data GProperty i where
ensureProperty (SimpleProperty d r) = r GIProperty :: Desc -> Propellor Result -> Info -> GProperty HasInfo
GSProperty :: Desc -> Propellor Result -> GProperty NoInfo
ensureProperty :: GProperty NoInfo -> Propellor Result
ensureProperty (GSProperty d r) = r
That works. I made a `gadtwip` git branch that elaborated on that,
to the point that Property.File compiles, but is otherwise
unfinished. Most definitions of `Property` need to be changed to
`GProperty NoInfo`, so that ensureProperty can call them. It's a big,
intrusive change, and it may complicate propellor too much.
(I may need to make instances of Prop for `GProperty NoInfo` and `GProperty
HasInfo`, if that's possible, and make more Property combinators work on
Prop.)