Skip to content

eliminate CoerceCat #52

Open
Open
@zliu41

Description

@zliu41

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

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions