Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix example #35

Open
wants to merge 42 commits into
base: typeclass-experiments
Choose a base branch
from

Conversation

sideeffffect
Copy link

No description provided.

The rules for export forwarders are changed as follows.

Previously, all export forwarders were declared `final`. Now, only term members are declared `final`. Type aliases left aside.

This makes it possible to export the same type member into several traits and then mix these traits in the same class. `typeclass-aggregates.scala` shows why this is essential to be able to combine multiple givens with type members.
The change does not lose safety since different type aliases would in any case lead to uninstantiatable classes.
Refinements of a class parent are added as synthetic members to the inheriting class.

# Conflicts:
#	compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
#	compiler/src/dotty/tools/dotc/typer/Implicits.scala
#	compiler/src/dotty/tools/dotc/typer/Namer.scala
#	tests/pos/typeclass-aggregates.scala
For a tracked class parameter we add a refinement in the constructor type that
the class member is the same as the parameter. E.g.
```scala
class C { type T }
class D(tracked val x: C) { type T = x.T }
```
This will generate the constructor type:
```scala
(x1: C): D { val x: x1.type }
```
Without `tracked` the refinement would not be added. This can solve several problems with dependent class
types where previously we lost track of type dependencies.
Make context bound evidence params tracked if they have types with abstract type members.
 - Don't rely on ContextBoundParamName for desugaring
 - For the first context bound [X: B ...], use `X` as the name of
   the evidence parameter for `B`.
If a context bound type `T` for type parameter `A` does not have
type parameters, demand evidence of type `T { type This = A }` instead.
Allow the RHS of a type def to be higher-kinded. But keep the
restriction for opaque type aliases; their RHS must be fully applied.
I am not sure why the restriction applies to them, but there was a
test specifically about that, so there night be a reason.

# Conflicts:
#	compiler/src/dotty/tools/dotc/typer/Typer.scala
A type implemented in a given definition can now be an infix type, without
enclosing parens being necessary.

By contrast, it cannot anymore be a refined type. Refined types have to be
enclosed in parens. This second point aligns the dotty parser with the
published syntax and the scala meta parser.
    given [A: Ord] => A is Ord:
      ...

    given [A: Ord] => A is Ord as listOrd:
      ...
"This" suggests the meaning "the type of this", which is not the role
of Self in type classes. Also Self is used in Swift and Rust, which have
a similar typeclass design.

# Conflicts:
#	compiler/src/dotty/tools/dotc/typer/Typer.scala
#	tests/pos/parsercombinators-arrow.scala
A definition like `given T = deferredSummon` in a trait will be
expanded to an abstract given in the trait that is implemented
automatically in all classes inheriting the trait.
Expand them to givens with deferred summons

# Conflicts:
#	compiler/src/dotty/tools/dotc/ast/Desugar.scala
Make sure that any references to a synthetic evidence parameter come
after that parameter is introduced.
Avoid accidental binding to self

# Conflicts:
#	compiler/src/dotty/tools/dotc/typer/Typer.scala
The idea is that `given ... = deferred` should be the new syntax for abstract givens. These
can only be defined in traits and need to be implemented in the first subclass extending the
trait. If the definition of a given vals is missing, one is synthesized by an implicit search
at the site of the extending class.

This will free the syntax

    given A is TC

for the more common case where we just want to implement a marker type class TC.

Also allow

# Conflicts:
#	compiler/src/dotty/tools/dotc/typer/Namer.scala
To make an abstract given with new style syntax, one needs to write
`= deferred`.
If a refined type has a parent type watching some other type, the parent
should not be mapped to Object. Previously, the parent counted as `isEmpty`
which caused this mapping.

Also: Complete and cleanup hylolib tests
odersky and others added 12 commits January 11, 2024 20:16
…5840

Faced with

    given C[T]:
      ...

(with a new line after `:`) we now classify this as new given syntax, and assume ... is a template body.
If one wants to use old syntax, one can still write

    given C[T]
      : ImplementedType ...

# Conflicts:
#	compiler/src/dotty/tools/dotc/parsing/Parsers.scala
We already reduce `R { type A = T } # A` to `T` in most situations when we
create types. We now also reduce `R { val x: S } # x` to `S` if `S` is a
singleton type.

This will simplify types as we go to more term-dependent typing. As a concrete
benefit, it will avoid several test-pickling failures due to pickling differences
when using dependent types.
Exclude synthetic, unnamed context bound evidence parameters.
# Conflicts:
#	compiler/src/dotty/tools/dotc/typer/Typer.scala
@sideeffffect
Copy link
Author

Hello @odersky , is this how the example is intended to work?

Copy link

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for the change to object Monoid, of course.

There's no need to explain parser combinators so early. The full code is given later in the examples.

@odersky odersky force-pushed the typeclass-experiments branch 3 times, most recently from 2cf69f8 to a63e4c4 Compare February 2, 2024 13:17
@odersky odersky force-pushed the typeclass-experiments branch 3 times, most recently from db16fdc to 3857796 Compare February 29, 2024 09:42
@odersky odersky force-pushed the typeclass-experiments branch 3 times, most recently from 3fe93ce to dc8c708 Compare March 31, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants