Skip to content

Automatically generate instances for Data.Typeable #2243

@rgrempel

Description

@rgrempel

I've been doing some work updating Data.Typeable.

One logical next step would be to have the compiler automatically derive instances for Data.Typeable. It is (at least conceptually) trivial, since it is basically an encoding of the type, which the compiler knows. In fact, it is more reliable to have the complier derive the instance than anything else, since the compiler has the most reliable knowledge of the type. (That is, human implementation could get out of sync with the actual type).

In fact, GHC now does even more than support deriving Typeable. It actually automatically generates an instance when needed, even without any explicit invocation of deriving. This would be especially desirable in Purescript, given the prohibition of orphan instances. Otherwise, every single module would need to add a deriving Typeable (or one would have to use the usual workarounds, such as a newtype etc.).

So, my question is this: if I were to implement automatic instance generation for Data.Typeable, is that something that would be considered desirable (and possibly mergeable)? Clearly, one wouldn't want to support this kind of thing in the compiler for very many purposes, but I think that Data.Typeable is arguably pretty fundamental.

One additional consideration is that Data.Typeable will probably change considerably when "kind polymorphism" (#1763) is available, in a manner similar to the equivalent changes in Haskell. I suppose that one could delay implementing automatic instance generation until kind polymorphism is available. However, I'm not sure whether there is any compelling reason to wait. That is, it may turn out that there is a technical reason why automatic instance generation depends on kind polymorphism, but it isn't obviously so (at least, it's not obvious to me).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions