Skip to content

Instantly share code, notes, and snippets.

@sidnt
Last active June 23, 2019 13:03
Show Gist options
  • Save sidnt/f7fb1e2e0984a6d7d6f3d92907408950 to your computer and use it in GitHub Desktop.
Save sidnt/f7fb1e2e0984a6d7d6f3d92907408950 to your computer and use it in GitHub Desktop.

When we have a type X, we can calculate the number of inhabitants type X has. IOW, the number of values that conform to that type.

If it's a primitive type, ie, if it doesn't depend on other types,

  • eg for Boolean, we know, it has only two inhabitants, true and false and that's by definition in Boolean Algebra. If we know that a value is of type boolean, we know, that it is either true or false.
  • eg, Int, we know, it has infinite inhabitants, as there are infinite many integers.

If it's a type composed of other types, the question becomes, in what manners can we build a type, that's composed of other types?

A generic sum type. type sumtype = A | B | C Either[Int,String] type prodtype = A & B & C (Int,String) type X = Int & String has no inhabitants while type X = Tuple2(Boolean,Boolean) has 4 inhabitants.

A generic product type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment