Haskell for Imperative Programmers #21 - data, type & newtype

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

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

  • @edvardm4348
    @edvardm4348 2 года назад +5

    These videos were in my opinion really, really well made. I'd put these videos to the same list of definite resources to go through along Hutton's Haskell book and LYAH.
    Thank you so much.

  • @VladTrishch
    @VladTrishch 4 года назад +11

    Love this series! Please, keep it up.

  • @kid-vf4lu
    @kid-vf4lu 4 года назад +11

    This is fantastic content! If you start a patreon, I will contribute

  • @arber10
    @arber10 2 года назад

    Very good explanation. Thanks!

  • @alexanderskusnov5119
    @alexanderskusnov5119 4 года назад +3

    1) I would add a record syntax:
    data RGB = RGB {red:: Int, green:: Int, blue:: Int}
    2) Why with record syntax I see an error?:
    newtype RGB = RGB {red:: Int, green:: Int, blue:: Int}
    but this case is legal?:
    newtype RGB = RGB (Int, Int, Int)

    • @philipphagenlocher
      @philipphagenlocher  4 года назад +7

      The second case doesn't work since red, green and blue are three distinct fields for the RGB constructor. Without the record syntax it would look like this: newtype RGB = RGB Int Int Int which isn't legal since the constructor has 3 fields.
      newtype RGB = RGB (Int, Int, Int) is legal since there is only one field (namely (Int, Int, Int) which is one tuple with some stuff in it).
      In general, using records in conjunction with newtype is not really helpful since only one field (and thus only one name) can be introduced to the type.