instance ToJSON (Carbs Volume) where ...
instance ToJSON (Carbs Mass) where ...
We're stuck, because Volume and Mass expand to types that mention type families (specifically, DimFactorsOf). Yet, the code above is quite reasonable. This is directly related to GHC#8828, which asks, essentially, for code like the above to work. But, I've decided (and SPJ agrees) that GHC#8828 is a bad idea, for other reasons.
What to do? Of course, wrapping in a newtype would work. Are there other ways? A few minutes' thought says no.
(Interesting, but ultimately failed idea: It seems straightforward(-ish) to write deepseq's force function at the type level, which would evaluate all type family applications in a type. The problem is that there's no way to get the evaluation started. Even if we had type Volume = Force (MkQu...), there's nothing forcing the RHS of the type synonym. I can't come up with a way around this. Any GHC feature request that comes to mind seems to be a stand-in for proper type pattern synonyms, as requested in the revised GHC#8828.)
Leaving this open as a ticket to either come up with a solution or to document a workaround.
Say we want
We're stuck, because
Volume
andMass
expand to types that mention type families (specifically,DimFactorsOf
). Yet, the code above is quite reasonable. This is directly related to GHC#8828, which asks, essentially, for code like the above to work. But, I've decided (and SPJ agrees) that GHC#8828 is a bad idea, for other reasons.What to do? Of course, wrapping in a newtype would work. Are there other ways? A few minutes' thought says no.
(Interesting, but ultimately failed idea: It seems straightforward(-ish) to write deepseq's
force
function at the type level, which would evaluate all type family applications in a type. The problem is that there's no way to get the evaluation started. Even if we hadtype Volume = Force (MkQu...)
, there's nothing forcing the RHS of the type synonym. I can't come up with a way around this. Any GHC feature request that comes to mind seems to be a stand-in for proper type pattern synonyms, as requested in the revised GHC#8828.)Leaving this open as a ticket to either come up with a solution or to document a workaround.