categorifier icon indicating copy to clipboard operation
categorifier copied to clipboard

eliminate `CoerceCat`

Open zliu41 opened this issue 3 years ago • 0 comments

We use coerceC to model Core's casts. However, it introduces some problems. For one, it basically duplicates the functionality of RepCat, but for different types (Coercible ones). The other problem is that it means all newtypes that are ever coerced need to have their constructors in scope whenever categorize is called. This is especially problematic for private constructors.

Conal has brought up this issue in both

  • https://github.com/conal/concat/issues/10 and
  • https://github.com/conal/concat/issues/34.

If we had something along the lines of

instance {-# overlappable #-} Newtype a b => HasRep a where
  type Rep a = b
  abst = Newtype.pack
  repr = Newtype.unpack

could we avoid the newtype constructor scoping issues? (At the expense of using DeriveAnyClass and deriving (Newtype) on all newtypes) If we manage to switch to Generics, this could be even simpler.

The complicated part being that Coercions get combined, so a coercion like TyConAppCo Representational sumTyCon [TyConAppCo Representational productTyCo []] would become abstC . abstC, not just a single abstC. I think we can approach this by inspecting the coercion and converting it into a composition of HasRep operations. Could be complicated to implement, though, because I'm not sure how to destructure Coercions, since they're all private.

(Extricated from https://kitty-hawk.atlassian.net/browse/SW-2657)

zliu41 avatar Apr 15 '22 20:04 zliu41