Scala 3: Path-Dependent Types, Methods and Functions

Поделиться
HTML-код
  • Опубликовано: 9 ноя 2024
  • НаукаНаука

Комментарии • 15

  • @alexandersviridov8682
    @alexandersviridov8682 2 года назад +1

    Nice. Now it's clear where this # in type lambda came from

  • @remidelmas9286
    @remidelmas9286 3 года назад +5

    you seem to have mixed things up: the Inner#Outer is called a type projection, the inner.Outer is a called a path dependent type, because it is prefixed by a object path. path dependent types are judged equal if their respective path prefixes can be resolved to the same stable object ref in the current scope

    • @luismiguelmejiasuarez2020
      @luismiguelmejiasuarez2020 3 года назад +1

      Also, note that type projections are being dropped from the language because they are unsound and in general it means that you could have just used a normal non-nested type. lptk.github.io/programming/2019/09/13/type-projection.html

    • @rockthejvm
      @rockthejvm  3 года назад

      Hm, thanks for the tip. The terminology seems a bit mixed in general, and that's how I made the most sense out of them. I'll read more on it and update the video as needed.
      I'm also aware that #T starting from an abstract path is not allowed anymore because it's not sound. I actually ran an exercise I used to show in Scala 2 with it, and it doesn't compile in Scala 3 anymore.

    • @DmytroMitin
      @DmytroMitin 3 года назад

      github.com/lampepfl/dotty-feature-requests/issues/14

  • @nerdwhisperer
    @nerdwhisperer 3 года назад +6

    These are great videos. More Scala 3 please!

  • @Jankoekepannekoek
    @Jankoekepannekoek 3 года назад +3

    At 4:38 you can guard against these equalities on incompatible types by using the new Multiversal Equality feature. I like like your videos btw, got me inspired to do the puzzles from Advent of Code using Scala 3.

    • @rockthejvm
      @rockthejvm  3 года назад

      Yep, this is true - wanted to point out how the objects are different.

  • @robertwatson7987
    @robertwatson7987 3 года назад +2

    Really interesting. Thanks.

  • @ericparnell9802
    @ericparnell9802 3 года назад +2

    Very clean explanation. Thank you.

  • @blacknick3931
    @blacknick3931 Год назад

    I try execute "println(innerA.getClass == innerB.getClass)" it return true. This make me confused. How it can be the same class but not the same type?
    detail is below:
    class Outer{class Inner}
    val outerA =new Outer;
    val innerA = new outerA.Inner;
    val outerB = new Outer;
    val innerB = new outerB.Inner;
    val inner:outerA.Inner = new outerB.Inner // as you said this wouldn't compile
    println(innerA.getClass == innerB.getClass) // but this line return true

    • @rockthejvm
      @rockthejvm  Год назад

      Inner classes being different and outer classes being the same are two different problems.
      innerA.getClass = Class[Outer]
      innerB.getClass = Class[Outer]
      They're the same.