Type Classes: Functions from Types to Terms
GADTs give us the ability to build up types alongside the values at the term level. In a sense, each GADT constructor is a function from its term level arguments to the type that the constructor returns. Type classes let us go the other direction, taking the type level information that we’ve built up with GADTs and generating new term level values. In this section, we’ll look at how you can use type classes alongside GADTs to get better type safety between different parts of your application.
We’ll start by continuing with the ShellCmd type that you built in the last section. Let’s imagine that we want to build an application that will let us create a set of pre-defined shell scripts that we’ve validated ...
Get Effective Haskell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.