Lesson 6: Working with newtypes

Contents
  • Introducing newtypes
  • Writing new types
  • Using our new types
  • Revising main
Video
  • 22 minutes
Tags
product type Either newtype

In this lesson we introduce some new types. We use newtypes that will help us distinguish at the type level between strings that represent inputs (password, username) and strings that represent errors.

We’d also like to keep a username and a password together as a User value, so we write a product type called User. We refactor the code we already have, write new functions that validate username inputs, and write a function that constructs a User from the conjunction of a valid Username and a valid Password.