Coercion and datatype contexts
This week we’ve written a couple articles covering some one-off topics that needed to be addressed:
How do you use the
coerce
function, and what types are coercible? TheThe discussion of coercion ties in very neatly to our previous page on deriving via; as it turns out, the two features are intimately related. documentation for theData.Coerce
module is very sparse, and it might lead you to thing that coercion isn’t very useful – But there are so many things to coerce! This is reflected in the many arrows we have drawn in our diagrams.Why can’t you put typeclass constraints on datatype definitions? As is often the case, you can if you enable a language extension. But it’s not a great idea, and the important lesson here is about understanding why.