Phantom Types and the Builder Pattern in Gleam • Hayleigh Thompson FOSDEM '24

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

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

  • @jleahr
    @jleahr 5 месяцев назад +2

    Congrats!!!
    really nice explanation of phantom types and gleam typing
    amazing language

  • @lpil
    @lpil 7 месяцев назад +6

    Bravo!

  • @bcpeinhardt
    @bcpeinhardt 7 месяцев назад

    The builder pattern application is really cool. I guess you could finagle it to be a convenient way to handle conditionally required fields as well 🤔

  • @Blubb3rbub
    @Blubb3rbub 5 месяцев назад +1

    I would like if there was a phantom type for integers that has information if a number can be 0 or not. So division could force you to check for != 0 at compile time.

    • @BooBoo314159
      @BooBoo314159 5 месяцев назад +1

      That can be made in your programs. I've thinking recently whether I should try to make a small package for this kind of things... I just don't know if it worth it, as one can just make their own custom types for this 😕

  • @lancemarchetti8673
    @lancemarchetti8673 6 месяцев назад +1

    Brilliant

  • @SimGunther
    @SimGunther 5 месяцев назад

    5:05 Isn't that why there are labeled parameters in the language to prevent this positional programming folly?
    In fact, at 12:40, it could be argued that labeled parameters & default values would also the builder pattern not too relevant had it not been for opaque types.

    • @hayleigh-dot-dev
      @hayleigh-dot-dev  5 месяцев назад +2

      Yeah labels can definitely help you distinguish parameters when they're all the same type, for sure! Labels are more about readability than correctness, though, and the compiler can never save if you get the *labels* the wrong way round. I don't think you should reach for this approach with phantom types for *everything* but it is definitely useful to have a way to express "structurally identical, nominally distinct"

  • @leepowelldev
    @leepowelldev 4 месяца назад

    Would phantoms types be considered similar to branded types?