Skip to content

Let traits with given clauses be implemented indirectly #7613

Closed
@travisbrown

Description

@travisbrown

Suppose you have a hierarchy like this:

trait Foo[A]
trait Bar[A] extends Foo[A]
trait Baz[A] extends Bar[A]

trait FooLaws[A] given Foo[A]
trait BarLaws[A] given Bar[A] extends FooLaws[A]
trait BazLaws[A] given Baz[A] extends BarLaws[A]

It'd be nice to be able to write something like this:

def instance[A] given Baz[A]: BazLaws[A] = new BazLaws[A] {}

Instead of:

def instance[A] given Baz[A]: BazLaws[A] =
  new BazLaws[A] with BarLaws[A] with FooLaws[A] {}

The former fails on the current nightly with:

1 |def instance[A] given Baz[A]: BazLaws[A] = new BazLaws[A] {}
  |                                           ^
  |          parameterized trait FooLaws is indirectly implemented,
  |          needs to be implemented directly so that arguments can be passed

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions