62: Getting Haskell Unit 3 - JSToElm
All Episodes

62: Getting Haskell Unit 3

Sticking with Types, we dive deeper with sum and product types, we hit on Semigroup and start to unwind Monoids!

Now on to programming with Types, Things are getting pretty good.

  • Creating types with and | or
  • Semigroups
  • Parameterized Types
  • The Maybe type

Start with some definitions

  • Algebraic data types: a composite type, meaning, any types that can be made by combining other types.

    • and / product types: combining two or more types, very common. nearly all languages have support for these. Structs in C. This can often be the only way to make new types.

    • This is the basis for class hierarchies. abstracting out what they have similar, and move downward. “real life is full of extreme edge cases”

    • Side note about data and declaring, or forming the data.

    • I really thought FP was function driven. But I’m not so sure I’d say that today. Yes yes functions as values are super important, but they more enable us to really focus on the structure and transformation of data, instead of actions or events on that data.

    • or / sum types: > In computer science, a tagged union, also called a variant, variant record, choice type, discriminated union, disjoint union, or sum type,

    • can take on several different, but fixed types. Like Bool

    • An instance of Bool can be either True or False

    • That Bool is a set containing all values True, False

    • Kinda like enums ? > An enumerated type can be seen as a degenerate case: a tagged union of unit types. It corresponds to a set of nullary constructors and may be implemented as a simple tag variable, since it holds no additional data besides the value of the tag.

    • datatype tree = Leaf
                | Node of (int * tree * tree)
    • Composability: creating something new by combining two like things together.

    • Like concat 2 lists together.

    • HOF that’s just a ( . ) called compose

      • it takes 2 functions for arguments example would be last item in a list last = head . reverse
    • Semigroup: type class with one important method the <> for combining instances that are of the same type.

    • (<>) : : Semigroup a => a -> a -> a

    • takes a value of type a, we don’t care what it is. and another of the same type, and returns a value that is of the same type as a, whatever that was to begin with.

    • Guards: do some computation on the arguments that are going to be compared.


Get Programming With Haskell


Published 13 Dec 2018

A show about learning Elm, Functional Programing, and generally leveling up as a JS developer.
JavaScript To Elm on Twitter