Generic typealiases with additional constraints?

Where clauses aren't supported on non-generic typealiases though, even though it seems useful:

protocol Differentiable {
  associatedtype TangentVector
}

// Doesn't work:
typealias EuclideanDifferentiable = Differentiable where TangentVector == Self

// Need to define a refinement protocol instead, adding burden to users:
protocol EuclideanDifferentiable: Differentiable where TangentVector == Self {}
typealias.swift:5:52: error: 'where' clause cannot be applied to a non-generic top-level declaration
typealias EuclideanDifferentiable = Differentiable where TangentVector == Self
                                                   ^

I wonder if supporting this makes sense at all?

I found a previous discussion about this, it seems like non-generic typealiases don't have any type parameters for where clauses to bind to.

1 Like