O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

  1. First, we defined a data type called Days. It has seven alternative values (Sunday to Saturday). The Days type can take, at the most, seven values.
  1. Next, we defined a data type called Variant. The Variant data type is classified by five type arguments. In the example, we used Int, Float, Double, Char, and String. The data type defines constructors Variant1 ... Variant5 with a field each corresponding to one type. At the same type, we also have a constructor Variant0, which does not have a field at all. Hence, the number of possible types that Variant can take is the sum of all possible values that each type can take. Additionally, we have to add one value for Variant0
  2. Since the number of possible values is the sum of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required