15-312 Recitation #10: Monads and Objects 2002-10-30 Joshua Dunfield (joshuad@cs) Carnegie Mellon University - Intuition for monads: 0tau (circle-tau) is like tau susp or 1 -> tau val(...) is like delay(...) or lambda _. ... let val is like force(...) or ...() The correspondence is very rough (tau susp does not separate out expressions e that have no effect when evaluated from expressions m that may have an effect, as monads do), but may be helpful. - Common mistakes on asst5: 1. Applying IH when there are no premises. You can only apply the IH to a *smaller* derivation; if there are no premises, there are no smaller derivations and you must prove what you need to prove without using the IH. 2. Making up notation. Not a big issue, but all the notation you needed was in the assignment. 3. Having write(v) write to the *beginning* of S_O. I assume this was due to people thinking the streams had to work the same way as in the SML stream module; you can't add something to the end of an SML stream, but the streams in the assignment are just abstract objects, so you *can* add something to the end. 4. Assuming stuff for the store monad carried over to the I/O monad. For example, you didn't need a store typing \Lambda since there was no store. 5. In the last two problems, answers that didn't typecheck. Practically everybody did this; only one person noticed that what they turned in couldn't possibly be well typed (and got full credit since I was so glad they were paying attention) - Solutions to last two asst5 problems: to appear - the Counter object from lecture in a monadic framework: counterRep = {x : int ref} counter = {get : 0int, inc: 01} ("01" is "circle unit") counterClass : counterRep -> counter newCounter : 0counter ...