Algebraic Data Type in Swift

updated 10 months ago; latest suggestion 9 months ago

This proposal has been withdrawn...

Swift has a powerful type system that we can compose multiple data into one (i.e. structs and enums) and decompose them using getters and pattern matching.

In functional programming, these types are called "product type" and "sum type" in which, as their names suggest, we can simply sum up or multiply types to create a new one. For example, Optional<T> = 1 + T, Result<T, E> = T + E, Result<Optional<T>, E> = 1 + T + E, etc. Believe it or not, we can play math (algebra) in Swift's type system!

In this talk, we will explore the basics of Algebraic Data Type and its related topics, such as "similarity of types", how Void and Never are similar but different, how "currying" actually works, and so on. We will also have a sneak-peek of underlying math called Category Theory.

Suggestions

  • 8b2f2d3e6553c2b4048b93300959895ab76b4154?size=100x100 8b2f2d3e6553c2b4048b93300959895ab76b4154 suggests 9 months ago

    What should attendees take away from this talk? It's okay for the end result to just be a general sense of "Hmm. That was interesting." But if you want them to use this information to accomplish something, that would be great to know too.

  • 7b66fb5480f4d6501b9f1be17661732bd39115c6?size=100x100 7b66fb5480f4d6501b9f1be17661732bd39115c6 suggests 10 months ago

    Any mention of Category Theory is always great in my view, but I think this suggestion would be more appealing if it also included some information on how to use the properties of these algebraic data types to model real world problems.

    This article is a pretty good example of applying these structures to real world problems: https://medium.com/@mttkay/refactoring-with-monoids-and-sum-types-part-1-bddc9ea61f5f

  • 419cdb2751e6a13b3e09323b6f44a9611c757a8b?size=100x100 419cdb2751e6a13b3e09323b6f44a9611c757a8b suggests 10 months ago

    This seems like a very interesting topic! I would love to hear more about this