Scala 3: Anti-Givens

Поділитися
Вставка
  • Опубліковано 23 січ 2025

КОМЕНТАРІ • 18

  • @luismiguelmejiasuarez2020
    @luismiguelmejiasuarez2020 3 роки тому +5

    One important note would be that just using a single type parameter is actually not enough for guarantee same type.
    For example if you pass a `List[String]` and a `List[Int]` the compiler will simply infer `Any` for `A` and thanks to Covariance and Liskov both lists would be applicable and of the same type.
    Using `=:=` fix this issue since we test for equality after inference.

  • @josephcagle
    @josephcagle 3 роки тому +1

    Great content! This channel deserves way more attention. Keep up the good work!

  • @leorandomnickname
    @leorandomnickname 3 роки тому +1

    interesting... is there an equivalent to NotGiven in Scala2 ?

    • @rockthejvm
      @rockthejvm  3 роки тому

      Yes, but not built-in. There is a way to exploit implicit ambiguity to make the code not compile: not because there isn't an implicit that satisfies the evidence, but because there are too many.

    • @tai-hao-le
      @tai-hao-le 3 роки тому

      @@rockthejvm can you give more details or make a video about it? :)

  • @jackgenewtf
    @jackgenewtf Рік тому +1

    I miss the pre-Scala 3 days when you could use IDEA without needing to frequently manually trigger a compile. :(

  • @aethermass
    @aethermass 3 роки тому +3

    Freaky. I can't imagine that I will ever use that..... but cool!!

  • @encapsulatio
    @encapsulatio 3 роки тому +1

    Any plans to convert all your courses for Scala 3 ?

    • @rockthejvm
      @rockthejvm  3 роки тому

      Recording as we speak!

    • @encapsulatio
      @encapsulatio 3 роки тому

      @@rockthejvm Is there any true "for complete beginners to programming" book or course in the Scala world? or is there any planned? I think many people(like me) would like to learn Scala truly from the start, and not depend on Python or Javascript courses for complete beginners to learn the fundamentals with one language just to waste time learning the particularities of that language and then need to learn from scratch Scala.

  • @StewartStewart
    @StewartStewart 3 роки тому

    FWIW, this is in the dotty reference page on givens (dotty.epfl.ch/docs/reference/contextual/givens.html), under the Negated Givens section.

  • @tuxjumale4197
    @tuxjumale4197 3 роки тому +1

    Thanks for the video, that's an interesting trick. But at the end you still had to modify the method's signature in every described solution. So as I understand, there is no way to do it without modifying or wrapping the original method? I expected that the final trick will be something like importing/declaring an implicit into the context, which changes the behaviour of the original method.

    • @rockthejvm
      @rockthejvm  3 роки тому +1

      In all cases we "wrapped" the original method. If you can change the method signature, you should add that extra argument list to enforce the type relationship.

    • @DmytroMitin
      @DmytroMitin Рік тому

      You can keep the original signature if you "hide" the implicit block with a macro in Scala 2 (inferImplicitValue) or inline method in Scala 3 (summonInline, summonFrom)

    • @DmytroMitin
      @DmytroMitin Рік тому

      There's no need to import or define new instances of NotGiven

  • @buthow900
    @buthow900 3 роки тому

    Thank you for this video :D

  • @BloodnutXcom
    @BloodnutXcom 3 роки тому

    Super cool!