Skip to content

Mixing polymorphism and templates. #75

@elfprince13

Description

@elfprince13

I'm working on a statically type-checked DSL. An expression node of type T has type Expr<T>, and definition of T itself (representing a literal) is something like class T : Expr<T>. There are a handful of Expr-subclasses that still have unbound type parameters (i.e. Let<U,T> binds variables of type U and returns a value of type T).

I would like to, at a minimum, be able to pattern match over bounded sets of possible U and T without resorting to (manual) copy-paste.

The annoying, but reasonably scalable for a small set of types, solution would be a copy-paste macro.

The nice and extensible solution would be some ability to pattern match based on a variance specification for template arguments: if A is a subtype of B, then being able to match an instance of Expr<A> in a pattern that specifies Expr<B> would be ideal (in Scala notation, the pattern would be for Expr<+B>).

I suspect I'm not the only person who would like to be able to do something like this, and I'm wondering what the obstacles are to implementation.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions