Hello, I'm going to talk about making impossible states with TypeScript and FPTS in a React application.
My name is Cristian Motochi and I am a software developer at Stackbuilders. And here I've been learning about Haskell and PureScript.
And there are two things that I like about these languages that I always try to make good languages or frameworks. First is static typing because that helps me to get errors as I am developing code and if something doesn't type check, OK, I won't be able to execute the code. I would have to fix that first. And functional programming because by composing functions I can define my program. I think the best way to get static typing in a realtification is with TypeScript. The type system is very rich. We have TypeAlysis, TypeUnions, interfaces, TypeVariables, and many more things. And combining TypeScript with Rambda or Rampdas code, we will get functional programming.
And that will be it, right? Nevertheless, recently I came across FPTS, which is a functional programming library that has a lot of features. It provides many things. It offers a lot of data types, like option to represent computations that may or may not exist, computations that may or may not fail, that's needed, nonempty arrays, and also data types to wrap async operations, that may or may not fail as well. And many more types. Also, some functional helpers, like this back function that we have here, which helps to define a data flow from top to bottom without the need of either numeric variables or defining a very long line of code, which may be hard to do. This one goes from top to bottom explaining what it is doing on every step. And the best part of FPTS is that it offers type classes and typing senses. Type classes are a good way to get added volumetricism. Here we have an example of the EnqueueType class with a type variable T, and we need to define an equals method to define a type instance of these type kits. We can define type instances defined in JavaScript objects and VConfig with complete types. We have many type classes defined in FPTS, monoids, functals, applicatives, monads, and many more. Let's combine JavaScript and FPTS to make impossible states, which is something that I learned back with John Feldman in this conference some years ago, as you can see. The purpose is to get compiler errors to avoid undecided states. Let's imagine the following example. We have this form to order a pizza, where we have the main selection and the main ingredient, then the second ingredient, which is optional, and the list of extra ingredients. And the main ingredient is not selected by default at the beginning. So we can think about the following data type to represent the data that we placed in that form. Which may be selected, the other not. A second ingredient, which is optional.
Comments