Why Should You Care About Referential Transparency?

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

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

  • @victorigbokwe6447
    @victorigbokwe6447 3 года назад +7

    The "Mob Boss" analogy had me cracking up throughout the video. :LOL!
    Thanks Daniel, for the RT explanation!

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

      (mob boss accent) Appreciate it!

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

    so if your method showMeMoney returns IO Int instead of Int, that would solve the issue because any call to showMeMoney would not 'pay respect' unless you run the monad, right? I'm trying to see why a monad would solve this issue.

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

      Yes and no, `Monads` on their own don't solve the issue, is the `IO` datatype the one that propose one solution to this issue (is not the only solution, and as with everything they all have tradeoffs).
      The `IO` datatype solves this problem because of what you described, by not longer executing the code but rather just being a description of the program to be run we recover RT; until the point the `IO` is run, that is why we say that should be the end of the world.
      Now, orthogonal to that we can also prove that the `IO` can form a `Monad`, this is irrelevant for the RT discussion but it has a big impact in the code we write, because `Monads` (and many other typeclasses from CT) give us tools on how to compose those `IO` together.
      That is why we can summarise FP on RT + composition; those two thins are what allow us to build bigger programs on top of small ones.
      With pure functions you have composition out of the box, the moment you add some context datatype like `Option` or `IO` we lose that out of the box composition; but `Monads` allow us to recover it.
      Note that this mix of `IO` with `Monads` is sometimes called "Program as values", where the main benefit we gain is being able to express control flow as functions.

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

      @@luismiguelmejiasuarez2020 Thanks. Even I barely understand the topic, I feel it is knowledgeable.

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

    Hi Daniel, a dumb question: as you mentioned in the video, we shouldn't use primitive types for money in practice. And what's the proper way to do so?

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

      No such thing as a dumb question! Use Decimal types or specialized libraries for money. The reason is that Doubles (the standard floating point standard) can't fully represend tenths and hundredths and maintain precision with math operations.

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

      @@rockthejvm Thank you, Daniel!

  • @patrick_gerd
    @patrick_gerd 8 месяцев назад

    Thank you

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

    💖💘❤💕💗