Skip to content

Instantly share code, notes, and snippets.

➚↗︎⬈

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?

object cli extends App {
val cli: IO[IOException, Unit] = for {
_ <- putStrLn("0. To exit\n1. One\n2. Two\n3. Three\n4. Four\n")
l <- getStrLn
_ <- Try(l.toInt) match {
case Success(c) => {
if(c == 0) IO.now(())
else if (c > 4) putStrLn(s"invalid input: " + c) *> cli
else putStrLn(s"got number: " + c) *> cli
/* in spark-shell */
import org.apache.spark.rdd.RDD
/* Q1 helpers */
type Input = (Int,Double)
type Output = Input
def f(r1: RDD[Input], r2: RDD[Input]):RDD[Output] = {
val cr:RDD[(Int,(Double,Double))] = r1 join r2
{ "allCssColors" : ["Black", "Navy", "DarkBlue", "MediumBlue", "Blue", "DarkGreen", "Green", "Teal", "DarkCyan", "DeepSkyBlue", "DarkTurquoise", "MediumSpringGreen", "Lime", "SpringGreen", "Aqua", "Cyan", "MidnightBlue", "DodgerBlue", "LightSeaGreen", "ForestGreen", "SeaGreen", "DarkSlateGray", "DarkSlateGrey", "LimeGreen", "MediumSeaGreen", "Turquoise", "RoyalBlue", "SteelBlue", "DarkSlateBlue", "MediumTurquoise", "Indigo", "DarkOliveGreen", "CadetBlue", "CornflowerBlue", "RebeccaPurple", "MediumAquaMarine", "DimGray", "DimGrey", "SlateBlue", "OliveDrab", "SlateGray", "SlateGrey", "LightSlateGray", "LightSlateGrey", "MediumSlateBlue", "LawnGreen", "Chartreuse", "Aquamarine", "Maroon", "Purple", "Olive", "Gray", "Grey", "SkyBlue", "LightSkyBlue", "BlueViolet", "DarkRed", "DarkMagenta", "SaddleBrown", "DarkSeaGreen", "LightGreen", "MediumPurple", "DarkViolet", "PaleGreen", "DarkOrchid", "YellowGreen", "Sienna", "Brown", "DarkGray", "DarkGrey", "LightBlue", "GreenYellow", "PaleTurquoise", "LightSteelBlue", "Pow