It creates a Schroedinger type which has two data constructors: an Opened constructor which takes a Probable object — that is, whose Live or Dead state is known — and an Unopened constructor which takes a random generator, and an object without a particular state, such as a Cat.
… If, however, you bind a function to an Opened box with a Live thing, it will apply the function to what’s in the box — in this case, the Cat itself.
… Here is the meat of this example, it’s reason for being, all contained within this one line: If you bind a function to an Unopened box, it gets bound in turn to an Opened box containing a Cat whose fate has been decided by the dice.
… This is fairly linear: it gets a random generator from the operating system, then creates an Unopened box and returns it, which gets printed. print does its work by calling show on the Schroedinger type, since it was derived from Show earlier.
Having just begun my descent down the rabbit hole, into a Haskell land of hiding grins and late late hatters, I thought I’d try journaling what I discover on the way, so that maybe those who are merely curious could play the part of language voyeur.
… This function starts out the list with 1, followed by 1, then it starts adding two lists together — provided by the same function before it’s even done!
…I kept thinking it was something I had to return as I went along, not passed down to each deeper level — and then returned after I’d added to it.
…If that first character is a colon, return a list with the current accumulator as the head, and recurse to process the rest of the string (and so on).
