The first two Scrap Your Boilerplate papers describe a way of writing generic functions that work for general types, but have special cases for specific types. For instance, fromJSON
from the aeson
package, defines a generic function for converting from JSON, but provides special cases for types like list or Int
:
parseJSON :: (Data a) => Value -> Parser a
parseJSON j = parseJSON_generic j
`ext1R` list
`ext1R` vector
`ext2R'` mapAny
`ext2R'` hashMapAny
-- Use the standard encoding for all base types.
`extR` (value :: F Integer)
`extR` (value :: F Int)
...
However, as the third SYB paper notes, "all the type-specific cases [need] to be supplied at once, when the recursive knot of generic function definition is tied". The paper then proposes a way to lift this restriction through the type-class mechanism.
The first two SYB papers are (with some modifications) part of the syb
package, but the third is not. Is there some other way of lifting the restriction that all type-specific cases need to be specified at once with the implementation of SYB on Hackage?