Skip to content

Instantly share code, notes, and snippets.

@bobbicodes
Last active November 13, 2022 19:55
Show Gist options
  • Save bobbicodes/ad434a6215966be09a8f76e40c1afdb3 to your computer and use it in GitHub Desktop.
Save bobbicodes/ad434a6215966be09a8f76e40c1afdb3 to your computer and use it in GitHub Desktop.
Transcript: YOW! 2013 Philip Wadler - The First Monad Tutorial #YOW (fetched using https://github.com/jdepoix/youtube-transcript-api)
[[{"text": "so this is the first monad tutorial", "start": 0.03, "duration": 8.34}, {"text": "these days there are lots of monad", "start": 3.54, "duration": 9.509}, {"text": "tutorials for Scala or Perl or I think", "start": 8.37, "duration": 7.229}, {"text": "that's channel 9 at Microsoft in the", "start": 13.049, "duration": 5.48}, {"text": "bottom corner and one called yet another", "start": 15.599, "duration": 6.151}, {"text": "presentation on loan ads and they have", "start": 18.529, "duration": 5.621}, {"text": "all sorts of complicated diagrams in", "start": 21.75, "duration": 5.15}, {"text": "them so you can point with this thing", "start": 24.15, "duration": 5.67}, {"text": "going what have we got here", "start": 26.9, "duration": 6.79}, {"text": "this is plumbing this is spacesuit this", "start": 29.82, "duration": 8.43}, {"text": "is burritos and this is funny boxes with", "start": 33.69, "duration": 8.04}, {"text": "balls in them but but remember that", "start": 38.25, "duration": 8.149}, {"text": "symbol okay that symbol is important", "start": 41.73, "duration": 4.669}, {"text": "right - you're all computer scientist so", "start": 48.5, "duration": 3.52}, {"text": "you're not scared by funny looking", "start": 50.61, "duration": 6.15}, {"text": "symbols right good actually we're quite", "start": 52.02, "duration": 7.519}, {"text": "are you scared by funny-looking symbols", "start": 56.76, "duration": 11.73}, {"text": "okay and you can get monads in all sorts", "start": 59.539, "duration": 12.821}, {"text": "of languages so you've got Haskell just", "start": 68.49, "duration": 5.46}, {"text": "go for your segments so this is very", "start": 72.36, "duration": 3.299}, {"text": "colorful pointer writing people", "start": 73.95, "duration": 4.08}, {"text": "sometimes get nervous but you don't need", "start": 75.659, "duration": 3.78}, {"text": "to be nervous as long as you're", "start": 78.03, "duration": 5.55}, {"text": "well-behaved and you can see the Haskell", "start": 79.439, "duration": 6.93}, {"text": "logo actually has built into it this air", "start": 83.58, "duration": 4.95}, {"text": "greater than greater than equal sign", "start": 86.369, "duration": 3.661}, {"text": "which is the monad thing as well as", "start": 88.53, "duration": 3.78}, {"text": "having a lambda built into it then we've", "start": 90.03, "duration": 5.82}, {"text": "got closure f-sharp g-sharp Scala Python", "start": 92.31, "duration": 5.28}, {"text": "we've already heard of Perl so there's", "start": 95.85, "duration": 3.78}, {"text": "lots of languages that use these things", "start": 97.59, "duration": 5.55}, {"text": "and a huge number of tutorials many of", "start": 99.63, "duration": 7.04}, {"text": "them based on some weird kind of analogy", "start": 103.14, "duration": 6.78}, {"text": "so here's the thing about this tutorial", "start": 106.67, "duration": 8.199}, {"text": "it will contain zero analogies and you", "start": 109.92, "duration": 6.87}, {"text": "might have heard that monads come from", "start": 114.869, "duration": 5.25}, {"text": "category theory I have a colleague who", "start": 116.79, "duration": 4.939}, {"text": "refers to category theory as", "start": 120.119, "duration": 6.741}, {"text": "intellectual terrorism so if you've been", "start": 121.729, "duration": 7.241}, {"text": "exposed to that kind of terrorism you", "start": 126.86, "duration": 3.849}, {"text": "might be worried but don't worry you", "start": 128.97, "duration": 4.349}, {"text": "need no category theory", "start": 130.709, "duration": 6.81}, {"text": "whatsoever to understand this talk okay", "start": 133.319, "duration": 7.381}, {"text": "all of you have the right background to", "start": 137.519, "duration": 6.75}, {"text": "understand this talk so please if I say", "start": 140.7, "duration": 5.909}, {"text": "something you don't understand raise", "start": 144.269, "duration": 5.881}, {"text": "your hand and ask a question okay I", "start": 146.609, "duration": 5.58}, {"text": "might accidentally forget to explain", "start": 150.15, "duration": 4.41}, {"text": "something you should be able to follow", "start": 152.189, "duration": 5.011}, {"text": "along if you can't please just ask a", "start": 154.56, "duration": 5.16}, {"text": "question if you're embarrassed to ask a", "start": 157.2, "duration": 5.28}, {"text": "question turn to the person next to you", "start": 159.72, "duration": 5.519}, {"text": "and say he just makes it suitable I", "start": 162.48, "duration": 4.289}, {"text": "don't know about puzzles you know about", "start": 165.239, "duration": 3.75}, {"text": "Mosel and maybe they'll say oh yeah", "start": 166.769, "duration": 4.981}, {"text": "whose lives of such and so but probably", "start": 168.989, "duration": 4.711}, {"text": "they'll take no I don't know about foods", "start": 171.75, "duration": 3.569}, {"text": "either and then you can raise your hand", "start": 173.7, "duration": 8.7}, {"text": "and ask okay oh yeah and then we thought", "start": 175.319, "duration": 12.301}, {"text": "of course all the means trapped in monad", "start": 182.4, "duration": 6.57}, {"text": "tutorial please help", "start": 187.62, "duration": 6.649}, {"text": "and the monad tutorials are coming and", "start": 188.97, "duration": 10.109}, {"text": "here is monad man I thought oh this is", "start": 194.269, "duration": 7.21}, {"text": "just something somebody found some", "start": 199.079, "duration": 5.55}, {"text": "superhero with an M on their chest but", "start": 201.479, "duration": 6.781}, {"text": "actually if you look down there you can", "start": 204.629, "duration": 6.92}, {"text": "see he really wanted a is Katie", "start": 208.26, "duration": 3.289}, {"text": "here.thank Katie for monad man a round", "start": 212.239, "duration": 7.53}, {"text": "of applause for KD and monad man", "start": 215.94, "duration": 3.829}, {"text": "and here's a graph of the amount of", "start": 222.58, "duration": 10.45}, {"text": "known monad tutorials and this is just", "start": 228.44, "duration": 6.99}, {"text": "for Haskell okay not any of the other", "start": 233.03, "duration": 4.679}, {"text": "languages and you notice that in the", "start": 235.43, "duration": 5.6}, {"text": "1990s it suddenly goes from zero to one", "start": 237.709, "duration": 9.331}, {"text": "that's the one you're about to see so", "start": 241.03, "duration": 10.17}, {"text": "here it is the first monad tutorial and", "start": 247.04, "duration": 8.52}, {"text": "I need to say maybe just a little bit to", "start": 251.2, "duration": 7.689}, {"text": "motivate why one would want a monad so", "start": 255.56, "duration": 7.88}, {"text": "monads are there we go there's me and", "start": 258.889, "duration": 11.121}, {"text": "I'm facing this tension so um to my", "start": 263.44, "duration": 12.43}, {"text": "right there is a lambda sign how many", "start": 270.01, "duration": 9.52}, {"text": "people recognize the lambda okay now all", "start": 275.87, "duration": 7.019}, {"text": "of you do good you know so I thought", "start": 279.53, "duration": 5.88}, {"text": "those nice silver one here that was made", "start": 282.889, "duration": 4.321}, {"text": "for me as a gift by one of my students", "start": 285.41, "duration": 5.1}, {"text": "so what lambda represents is the lambda", "start": 287.21, "duration": 6.0}, {"text": "calculus and more importantly a nice", "start": 290.51, "duration": 5.64}, {"text": "sound simple theoretical basis for", "start": 293.21, "duration": 5.16}, {"text": "computing that has no side effects", "start": 296.15, "duration": 5.76}, {"text": "whatsoever right normally when somebody", "start": 298.37, "duration": 5.85}, {"text": "explains computing to you the first time", "start": 301.91, "duration": 3.75}, {"text": "they say well there's a variable here", "start": 304.22, "duration": 3.18}, {"text": "and that's a box and you put stuff in", "start": 305.66, "duration": 3.72}, {"text": "the box and immediately you're often", "start": 307.4, "duration": 4.62}, {"text": "analogies lambda calculus can be", "start": 309.38, "duration": 5.28}, {"text": "explained very simply you have a term", "start": 312.02, "duration": 6.33}, {"text": "and it's equal to another term which is", "start": 314.66, "duration": 6.9}, {"text": "equal to another term and everything can", "start": 318.35, "duration": 5.819}, {"text": "be explained by substituting equals for", "start": 321.56, "duration": 5.57}, {"text": "equals and that's it so it's a wonderful", "start": 324.169, "duration": 8.971}, {"text": "simple model of computing and that's", "start": 327.13, "duration": 7.75}, {"text": "what we want to make use of now I know", "start": 333.14, "duration": 3.18}, {"text": "not all of you are convinced by that", "start": 334.88, "duration": 5.7}, {"text": "that's fine but you all will be right", "start": 336.32, "duration": 7.14}, {"text": "this is how the world is moving right", "start": 340.58, "duration": 5.28}, {"text": "twenty years ago nobody is using Haskell", "start": 343.46, "duration": 6.9}, {"text": "these days it's used at major banks the", "start": 345.86, "duration": 6.36}, {"text": "main - Haskell developers our time and", "start": 350.36, "duration": 3.199}, {"text": "Peyton Jones in time and Marlowe", "start": 352.22, "duration": 3.469}, {"text": "they were both at Microsoft Simon", "start": 353.559, "duration": 3.45}, {"text": "Marlowe's just been hired away by", "start": 355.689, "duration": 2.3}, {"text": "Facebook", "start": 357.009, "duration": 3.69}, {"text": "lots of people these days are using", "start": 357.989, "duration": 6.88}, {"text": "functional languages because when", "start": 360.699, "duration": 6.78}, {"text": "there's no side effects the interface to", "start": 364.869, "duration": 4.59}, {"text": "the function tells you everything there", "start": 367.479, "duration": 5.52}, {"text": "is to know and that level of modularity", "start": 369.459, "duration": 8.3}, {"text": "is really helpful in developing programs", "start": 372.999, "duration": 7.13}, {"text": "okay so the great thing is it makes", "start": 377.759, "duration": 6.07}, {"text": "everything completely obvious and that", "start": 380.129, "duration": 5.62}, {"text": "gives you great structuring properties", "start": 383.829, "duration": 4.59}, {"text": "and in particular these days when we", "start": 385.749, "duration": 4.95}, {"text": "want to make things concurrent it's very", "start": 388.419, "duration": 5.34}, {"text": "helpful because if something's making", "start": 390.699, "duration": 5.49}, {"text": "use of assignment and of two concurrent", "start": 393.759, "duration": 3.93}, {"text": "things making use of assignments you", "start": 396.189, "duration": 2.7}, {"text": "have to worry about how those", "start": 397.689, "duration": 3.99}, {"text": "assignments interleave right shared", "start": 398.889, "duration": 6.87}, {"text": "memory is the root of all evil so if", "start": 401.679, "duration": 5.58}, {"text": "you're in a pure functional language", "start": 405.759, "duration": 4.32}, {"text": "there's no assignment it's much easier", "start": 407.259, "duration": 5.49}, {"text": "to get things to work concurrently or in", "start": 410.079, "duration": 6.56}, {"text": "parallel I'm not saying it's easy but", "start": 412.749, "duration": 6.84}, {"text": "I'm saying that by not having to worry", "start": 416.639, "duration": 5.17}, {"text": "about lots of assignment going on you", "start": 419.589, "duration": 4.41}, {"text": "can focus on the real important problems", "start": 421.809, "duration": 5.64}, {"text": "in making something concurrent ok so", "start": 423.999, "duration": 6.3}, {"text": "functional programming there me with my", "start": 427.449, "duration": 6.36}, {"text": "lambda everything is wonderful I'll show", "start": 430.299, "duration": 5.76}, {"text": "you how wonderful right my daughter is", "start": 433.809, "duration": 4.26}, {"text": "old enough it and she now makes stuffed", "start": 436.059, "duration": 4.801}, {"text": "fuzzy toys to give to me rather than me", "start": 438.069, "duration": 4.77}, {"text": "giving them to her this is the land that", "start": 440.86, "duration": 7.229}, {"text": "she gave me okay and it's fuzzy I want", "start": 442.839, "duration": 7.08}, {"text": "you to think about that right lenses are", "start": 448.089, "duration": 5.01}, {"text": "fuzzy comfortable things but they're not", "start": 449.919, "duration": 5.31}, {"text": "scary theory they are your friends you", "start": 453.099, "duration": 4.38}, {"text": "want to cuddle up to them they want to", "start": 455.229, "duration": 6.15}, {"text": "cuddle up to you okay so everything's", "start": 457.479, "duration": 5.06}, {"text": "wonderful", "start": 461.379, "duration": 6.42}, {"text": "so why on my other side am i plagued by", "start": 462.539, "duration": 7.33}, {"text": "these three demons what are these three", "start": 467.799, "duration": 5.43}, {"text": "demons so we've got the the up arrow of", "start": 469.869, "duration": 7.17}, {"text": "exception raising the Kohen equal of", "start": 473.229, "duration": 8.61}, {"text": "assignment the great evil and the curly", "start": 477.039, "duration": 9.84}, {"text": "sheet of output and remember I said two", "start": 481.839, "duration": 5.461}, {"text": "great", "start": 486.879, "duration": 2.82}, {"text": "thing about pure functional programming", "start": 487.3, "duration": 7.01}, {"text": "is it makes it completely obvious", "start": 489.699, "duration": 10.771}, {"text": "everything that's going on but indeed it", "start": 494.31, "duration": 8.56}, {"text": "can sometimes make things painfully", "start": 500.47, "duration": 6.99}, {"text": "obvious right you have a lot of detail", "start": 502.87, "duration": 6.539}, {"text": "in those cases where you actually do", "start": 507.46, "duration": 4.32}, {"text": "need to pass around state and it does", "start": 509.409, "duration": 6.51}, {"text": "happen right passing that around can get", "start": 511.78, "duration": 7.77}, {"text": "a bit painful so there's things for", "start": 515.919, "duration": 5.61}, {"text": "which sometimes you would think yep", "start": 519.55, "duration": 4.109}, {"text": "exception handling is just the thing", "start": 521.529, "duration": 4.591}, {"text": "outputs just the thing assignment is", "start": 523.659, "duration": 4.351}, {"text": "just the thing and when you need them in", "start": 526.12, "duration": 3.63}, {"text": "your in a pure language what you're", "start": 528.01, "duration": 7.35}, {"text": "going to do not Ghostbusters monads okay", "start": 529.75, "duration": 7.98}, {"text": "so that's what we're going to do so", "start": 535.36, "duration": 4.169}, {"text": "you're ready to program we're actually", "start": 537.73, "duration": 3.33}, {"text": "going to do some coding here are you", "start": 539.529, "duration": 5.18}, {"text": "ready to code are you ready to code", "start": 541.06, "duration": 5.969}, {"text": "let's see we'll skip over that from are", "start": 544.709, "duration": 9.88}, {"text": "you ready to code in Haskell how about", "start": 547.029, "duration": 9.3}, {"text": "are you ready to code in Scala", "start": 554.589, "duration": 5.071}, {"text": "oh that's less maybe we should go back", "start": 556.329, "duration": 6.781}, {"text": "to the Haskell talk right so I gave the", "start": 559.66, "duration": 6.81}, {"text": "talk in Haskell last time and lots of", "start": 563.11, "duration": 5.76}, {"text": "people hood and one reason they went is", "start": 566.47, "duration": 4.619}, {"text": "perfectly reasonable which is rewrite", "start": 568.87, "duration": 4.14}, {"text": "function application differently and I", "start": 571.089, "duration": 3.661}, {"text": "even forgot to explain that clearly at", "start": 573.01, "duration": 3.12}, {"text": "the beginning which is why you have to", "start": 574.75, "duration": 3.3}, {"text": "all ask questions if you don't", "start": 576.13, "duration": 3.149}, {"text": "understand I'm not going to blame myself", "start": 578.05, "duration": 3.45}, {"text": "for not explaining nobody in the", "start": 579.279, "duration": 5.701}, {"text": "audience asked who on them yeah no I", "start": 581.5, "duration": 4.829}, {"text": "should have explained it's really my", "start": 584.98, "duration": 5.849}, {"text": "fault but ask anyway so this time around", "start": 586.329, "duration": 6.87}, {"text": "so that function application is written", "start": 590.829, "duration": 3.421}, {"text": "in the style that looks more familiar", "start": 593.199, "duration": 3.241}, {"text": "and I think that actually is very", "start": 594.25, "duration": 5.07}, {"text": "helpful for audiences indeed my new", "start": 596.44, "duration": 5.55}, {"text": "functional language length uses that", "start": 599.32, "duration": 4.86}, {"text": "style of function application so we're", "start": 601.99, "duration": 4.68}, {"text": "going to do it in Scala you can see it", "start": 604.18, "duration": 4.8}, {"text": "in a more familiar way and long the way", "start": 606.67, "duration": 3.96}, {"text": "we'll see some definitions of the word", "start": 608.98, "duration": 5.099}, {"text": "monad so it actually monad noun 1", "start": 610.63, "duration": 7.519}, {"text": "philosophy any fundamental entity", "start": 614.079, "duration": 6.631}, {"text": "especially if autonomous on", "start": 618.149, "duration": 3.731}, {"text": "sure that makes you feel much better", "start": 620.71, "duration": 5.73}, {"text": "okay so there it is in Haskell and I", "start": 621.88, "duration": 6.18}, {"text": "think there's one other thing that", "start": 626.44, "duration": 4.71}, {"text": "really threw people which is like I said", "start": 628.06, "duration": 6.06}, {"text": "it in an italic font so it looks all", "start": 631.15, "duration": 5.85}, {"text": "pretty like mathematics and everybody", "start": 634.12, "duration": 6.72}, {"text": "said Oh mathematics I am not worthy but", "start": 637.0, "duration": 5.97}, {"text": "don't be afraid of mathematics right", "start": 640.84, "duration": 4.53}, {"text": "mathematics is warm and fuzzy and cuddly", "start": 642.97, "duration": 6.09}, {"text": "just like lambdas right are both not", "start": 645.37, "duration": 6.66}, {"text": "many many years ago said if you have a", "start": 649.06, "duration": 4.74}, {"text": "problem they're susceptible to", "start": 652.03, "duration": 5.67}, {"text": "mathematics and you don't use it it is", "start": 653.8, "duration": 5.85}, {"text": "as if you were in the dark and you", "start": 657.7, "duration": 7.26}, {"text": "failed to light a candle mathematics is", "start": 659.65, "duration": 7.8}, {"text": "your friend don't be afraid of it hey", "start": 664.96, "duration": 4.83}, {"text": "you guys can all cope with JavaScript of", "start": 667.45, "duration": 3.96}, {"text": "course you can do with deal with", "start": 669.79, "duration": 5.64}, {"text": "mathematics okay", "start": 671.41, "duration": 7.2}, {"text": "so here's some Scala and what we're", "start": 675.43, "duration": 6.63}, {"text": "going to do is write out a very simple", "start": 678.61, "duration": 5.82}, {"text": "evaluator for arithmetic as a way of", "start": 682.06, "duration": 4.68}, {"text": "motivating why you might want monads and", "start": 684.43, "duration": 5.79}, {"text": "so we just have terms and the term is", "start": 686.74, "duration": 6.15}, {"text": "built in one of two ways it's either a", "start": 690.22, "duration": 5.64}, {"text": "con for constant which contains an", "start": 692.89, "duration": 6.84}, {"text": "integer or it's a div which contains two", "start": 695.86, "duration": 6.27}, {"text": "other terms so these are going to be", "start": 699.73, "duration": 4.56}, {"text": "parse trees representing arithmetic", "start": 702.13, "duration": 4.08}, {"text": "problems built solely from constants and", "start": 704.29, "duration": 5.43}, {"text": "division so for instance here's a term", "start": 706.21, "duration": 6.87}, {"text": "that represents 1932 divided by 2 and", "start": 709.72, "duration": 6.69}, {"text": "then you divide that by 23 okay and", "start": 713.08, "duration": 5.37}, {"text": "here's another term that represents 1", "start": 716.41, "duration": 6.42}, {"text": "divided by 0 nod if you're happy with", "start": 718.45, "duration": 8.73}, {"text": "that most people are not nodding I'm", "start": 722.83, "duration": 8.85}, {"text": "just going to stop right not if you are", "start": 727.18, "duration": 7.16}, {"text": "happy with that", "start": 731.68, "duration": 2.66}, {"text": "you're not nodding ask a question", "start": 735.45, "duration": 4.38}, {"text": "I'll try a third time nod if you're", "start": 740.55, "duration": 5.49}, {"text": "happy with that", "start": 743.98, "duration": 4.26}, {"text": "you're still not nodding you really", "start": 746.04, "duration": 7.33}, {"text": "better ask your question shouldn't the", "start": 748.24, "duration": 7.019}, {"text": "type system stop you from dividing by", "start": 753.37, "duration": 5.67}, {"text": "zero no so yesterday the Croft I", "start": 755.259, "duration": 7.14}, {"text": "mentioned this theorem of Robin Millers", "start": 759.04, "duration": 7.589}, {"text": "well hike programs don't go wrong but", "start": 762.399, "duration": 6.661}, {"text": "wrong has a very specific definition in", "start": 766.629, "duration": 4.5}, {"text": "the newspaper which you met forgot to", "start": 769.06, "duration": 3.959}, {"text": "mention and the specific definition", "start": 771.129, "duration": 4.621}, {"text": "basically means that something like", "start": 773.019, "duration": 6.081}, {"text": "adding a number to a string that's wrong", "start": 775.75, "duration": 6.569}, {"text": "trying to apply a number rather than", "start": 779.1, "duration": 5.89}, {"text": "apply a function that's wrong but", "start": 782.319, "duration": 4.741}, {"text": "dividing one by zero that's not wrong", "start": 784.99, "duration": 5.339}, {"text": "that's bottom so we will catch certain", "start": 787.06, "duration": 5.85}, {"text": "errors but not others so no the type", "start": 790.329, "duration": 4.021}, {"text": "system doesn't prevent you from doing", "start": 792.91, "duration": 3.84}, {"text": "every stupid thing just some stupid", "start": 794.35, "duration": 4.94}, {"text": "things excellent question thank you", "start": 796.75, "duration": 6.689}, {"text": "third time know if you're happy with", "start": 799.29, "duration": 8.409}, {"text": "that all right that's enough naught so I", "start": 803.439, "duration": 6.77}, {"text": "can move on", "start": 807.699, "duration": 2.51}, {"text": "so now we'll write a little evaluator", "start": 810.629, "duration": 5.531}, {"text": "writing it in Scala I'm not that useful", "start": 812.86, "duration": 5.31}, {"text": "Scala so you guys can correct me if I", "start": 816.16, "duration": 4.229}, {"text": "get anything wrong right so eat an", "start": 818.17, "duration": 4.83}, {"text": "evaluator takes a term and it returns an", "start": 820.389, "duration": 4.351}, {"text": "integer and we're going to match on that", "start": 823.0, "duration": 3.54}, {"text": "term and there are two possibilities", "start": 824.74, "duration": 4.17}, {"text": "right it's either a constant or division", "start": 826.54, "duration": 4.62}, {"text": "if it's a constant just return that", "start": 828.91, "duration": 4.619}, {"text": "constant if it's a division evaluate", "start": 831.16, "duration": 4.38}, {"text": "both of the sub terms and then divide", "start": 833.529, "duration": 8.16}, {"text": "the result okay pretty clear okay and", "start": 835.54, "duration": 8.159}, {"text": "then of course if we set a to the result", "start": 841.689, "duration": 4.32}, {"text": "evaluating answer that's a it always is", "start": 843.699, "duration": 4.74}, {"text": "42 you did all that bill did that", "start": 846.009, "duration": 6.0}, {"text": "division right why did I pick the 1932", "start": 848.439, "duration": 5.19}, {"text": "so starting point by the way that's the", "start": 852.009, "duration": 2.971}, {"text": "year in which lambda calculus was", "start": 853.629, "duration": 1.95}, {"text": "invented", "start": 854.98, "duration": 2.609}, {"text": "how many programming languages do you", "start": 855.579, "duration": 3.961}, {"text": "know that were invented before there", "start": 857.589, "duration": 5.761}, {"text": "were any computers lambda calculus is", "start": 859.54, "duration": 6.51}, {"text": "cool okay and then of course if we try", "start": 863.35, "duration": 5.31}, {"text": "to divide by zero then it's the computer", "start": 866.05, "duration": 5.009}, {"text": "explodes right it gives us a divided by", "start": 868.66, "duration": 3.28}, {"text": "zero error", "start": 871.059, "duration": 2.861}, {"text": "we are going to do something about that", "start": 871.94, "duration": 6.44}, {"text": "divide by zero error by the way more RAM", "start": 873.92, "duration": 7.85}, {"text": "that won't help", "start": 878.38, "duration": 3.39}, {"text": "so what are we going to do right what we", "start": 883.749, "duration": 5.32}, {"text": "want if we're trying to divide by zero", "start": 887.299, "duration": 4.08}, {"text": "we want to raise an exception so in the", "start": 889.069, "duration": 4.05}, {"text": "language with side-effects that's easy", "start": 891.379, "duration": 4.5}, {"text": "in a functional language it's also very", "start": 893.119, "duration": 5.52}, {"text": "easy all you need to do is rewrite the", "start": 895.879, "duration": 5.76}, {"text": "entire program so let's see how we would", "start": 898.639, "duration": 8.16}, {"text": "rewrite the entire program so my", "start": 901.639, "duration": 6.18}, {"text": "exception is going to be an error", "start": 906.799, "duration": 2.94}, {"text": "message let's call make let's make those", "start": 907.819, "duration": 3.87}, {"text": "strings and I'm going to find a type", "start": 909.739, "duration": 5.371}, {"text": "called M of a so it's a parameterised", "start": 911.689, "duration": 5.851}, {"text": "type the type is called m and takes a", "start": 915.11, "duration": 5.159}, {"text": "type parameter which is an a what M of a", "start": 917.54, "duration": 5.19}, {"text": "means is a computation that returns a", "start": 920.269, "duration": 8.04}, {"text": "value of type a so in our case so and", "start": 922.73, "duration": 6.839}, {"text": "what is M of a there are two", "start": 928.309, "duration": 1.981}, {"text": "possibilities", "start": 929.569, "duration": 6.0}, {"text": "it's either a raise of an exception so", "start": 930.29, "duration": 10.769}, {"text": "string or its return of an A so right if", "start": 935.569, "duration": 7.71}, {"text": "we return a value of type a we just", "start": 941.059, "duration": 4.47}, {"text": "return it and otherwise we're going to", "start": 943.279, "duration": 3.87}, {"text": "raise an exception so computation does", "start": 945.529, "duration": 4.321}, {"text": "one of two things it raises an exception", "start": 947.149, "duration": 4.711}, {"text": "that is it returns the string as an", "start": 949.85, "duration": 3.81}, {"text": "error message or it returns a value of", "start": 951.86, "duration": 4.169}, {"text": "type a so that's what M of a means in", "start": 953.66, "duration": 6.329}, {"text": "this case see it's easy you just rewrite", "start": 956.029, "duration": 7.05}, {"text": "the whole evaluator so what do we do", "start": 959.989, "duration": 5.491}, {"text": "here um I'll just point at the string", "start": 963.079, "duration": 4.38}, {"text": "rather than turning round can people see", "start": 965.48, "duration": 5.25}, {"text": "that little hand yep okay so we've got s", "start": 967.459, "duration": 5.91}, {"text": "which is a term and we match it right in", "start": 970.73, "duration": 5.269}, {"text": "the two possibility if use a con or div", "start": 973.369, "duration": 5.19}, {"text": "so if it's con of course we just return", "start": 975.999, "duration": 4.541}, {"text": "a so notice now we have to write return", "start": 978.559, "duration": 5.07}, {"text": "around a and notice that the good thing", "start": 980.54, "duration": 5.519}, {"text": "about a type system is that you just", "start": 983.629, "duration": 4.92}, {"text": "said a and you forgot the return the", "start": 986.059, "duration": 4.02}, {"text": "type system would say did you really", "start": 988.549, "duration": 4.561}, {"text": "mean that I don't think so and you'd put", "start": 990.079, "duration": 5.01}, {"text": "in the return to give it the right type", "start": 993.11, "duration": 5.339}, {"text": "which is in this case M event this works", "start": 995.089, "duration": 6.33}, {"text": "right because a is an int so otherwise", "start": 998.449, "duration": 5.43}, {"text": "it's a div of T nu and we're going to", "start": 1001.419, "duration": 5.371}, {"text": "we'll evaluate T of course T is going to", "start": 1003.879, "duration": 4.65}, {"text": "do one of two things it's either going", "start": 1006.79, "duration": 3.779}, {"text": "to give an error message if it does that", "start": 1008.529, "duration": 4.321}, {"text": "will just return that same error message", "start": 1010.569, "duration": 4.49}, {"text": "or", "start": 1012.85, "duration": 2.209}, {"text": "it's going to return some value let's", "start": 1015.1, "duration": 3.42}, {"text": "call it a and then the schools can", "start": 1016.39, "duration": 4.02}, {"text": "evaluate you and it'll do the same thing", "start": 1018.52, "duration": 3.81}, {"text": "if it gives an error message we'll", "start": 1020.41, "duration": 6.36}, {"text": "return it so I will raise it and if it", "start": 1022.33, "duration": 6.57}, {"text": "gives the value B well we'll check and", "start": 1026.77, "duration": 4.41}, {"text": "if B is 0 will give an error message", "start": 1028.9, "duration": 5.01}, {"text": "divided by 0 and otherwise we'll return", "start": 1031.18, "duration": 6.27}, {"text": "a over B so you said why doesn't the", "start": 1033.91, "duration": 5.34}, {"text": "type system get rid of you know tell me", "start": 1037.45, "duration": 3.57}, {"text": "that I'm dividing by 0 so it won't do", "start": 1039.25, "duration": 3.66}, {"text": "that but if you want to say well the", "start": 1041.02, "duration": 5.88}, {"text": "answer is either a value of type A or an", "start": 1042.91, "duration": 5.76}, {"text": "error message it will help you get that", "start": 1046.9, "duration": 6.09}, {"text": "right okay so all we had to do was", "start": 1048.67, "duration": 5.73}, {"text": "rewrite the program in this route", "start": 1052.99, "duration": 3.9}, {"text": "straight forward but revoltingly tedious", "start": 1054.4, "duration": 6.99}, {"text": "way let's try another possibility", "start": 1056.89, "duration": 6.75}, {"text": "oh no let's try it first let's just make", "start": 1061.39, "duration": 6.0}, {"text": "sure it works so let em be eval of", "start": 1063.64, "duration": 8.15}, {"text": "answer and n is going to be return of 42", "start": 1067.39, "duration": 7.56}, {"text": "but now if we do the dare err we get", "start": 1071.79, "duration": 7.96}, {"text": "raised of divided by 0 okay any", "start": 1074.95, "duration": 8.43}, {"text": "questions yet I had a question I've saw", "start": 1079.75, "duration": 5.7}, {"text": "this when I was working on it with Jed", "start": 1083.38, "duration": 4.32}, {"text": "and Toby we're very very helpful and", "start": 1085.45, "duration": 3.42}, {"text": "there will be a special thanks to them", "start": 1087.7, "duration": 3.66}, {"text": "at the end but I said why aren't there", "start": 1088.87, "duration": 3.93}, {"text": "quotation marks around four divided by", "start": 1091.36, "duration": 2.61}, {"text": "zero and they said well that's what", "start": 1092.8, "duration": 5.03}, {"text": "Scala does okay that's what scholar does", "start": 1093.97, "duration": 3.86}, {"text": "so let's look at a different thing to do", "start": 1099.81, "duration": 5.26}, {"text": "we want to count the number of division", "start": 1102.46, "duration": 5.22}, {"text": "operations so that's really easy if you", "start": 1105.07, "duration": 5.67}, {"text": "have global state you can just increment", "start": 1107.68, "duration": 4.53}, {"text": "the global state every time you do a", "start": 1110.74, "duration": 5.13}, {"text": "division operation but what if you don't", "start": 1112.21, "duration": 6.15}, {"text": "have state well that's really easy too", "start": 1115.87, "duration": 4.65}, {"text": "all we need to do is rewrite the entire", "start": 1118.36, "duration": 4.67}, {"text": "program so how are we going to do that", "start": 1120.52, "duration": 5.55}, {"text": "well now let's let's our state be an", "start": 1123.03, "duration": 4.36}, {"text": "integer the count of the number of", "start": 1126.07, "duration": 3.57}, {"text": "division operations and something of", "start": 1127.39, "duration": 6.08}, {"text": "type M of a is the computation that", "start": 1129.64, "duration": 7.35}, {"text": "updates the state and returns a value of", "start": 1133.47, "duration": 5.83}, {"text": "type a so it takes the current state as", "start": 1136.99, "duration": 5.19}, {"text": "input and it returns a pair of a the", "start": 1139.3, "duration": 6.47}, {"text": "answer whose type is a and the new state", "start": 1142.18, "duration": 6.79}, {"text": "so function from current state to", "start": 1145.77, "duration": 6.86}, {"text": "answer a new state so now eval is going", "start": 1148.97, "duration": 5.699}, {"text": "to take a term and return an M of int", "start": 1152.63, "duration": 6.84}, {"text": "and we'll match s and if it's a constant", "start": 1154.669, "duration": 7.26}, {"text": "then we don't change the state at all so", "start": 1159.47, "duration": 4.62}, {"text": "we take as input the state X and we", "start": 1161.929, "duration": 6.811}, {"text": "return an ax pair okay", "start": 1164.09, "duration": 7.62}, {"text": "take the input state return the answer", "start": 1168.74, "duration": 5.64}, {"text": "which is in this case a and return the", "start": 1171.71, "duration": 4.8}, {"text": "same state unchanged state doesn't", "start": 1174.38, "duration": 6.06}, {"text": "change no assignment okay so this arrow", "start": 1176.51, "duration": 6.18}, {"text": "here this is Scala's wave writing lambda", "start": 1180.44, "duration": 4.92}, {"text": "in lambda calculus you'd write lambda X", "start": 1182.69, "duration": 7.619}, {"text": "of type int returns and a X pair okay", "start": 1185.36, "duration": 7.049}, {"text": "not if you're happy you know what will", "start": 1190.309, "duration": 5.011}, {"text": "happen if you don't nod not if you're", "start": 1192.409, "duration": 8.581}, {"text": "happy you're not nodding ah you're", "start": 1195.32, "duration": 9.989}, {"text": "nodding imperceptibly okay we'll move on", "start": 1200.99, "duration": 6.569}, {"text": "any questions I'm not getting enough", "start": 1205.309, "duration": 4.921}, {"text": "questions here any questions okay", "start": 1207.559, "duration": 5.73}, {"text": "this is boring right it's easy to do but", "start": 1210.23, "duration": 4.59}, {"text": "it's boring it's tedious please", "start": 1213.289, "duration": 3.75}, {"text": "straightforward so if now if we're", "start": 1214.82, "duration": 4.56}, {"text": "dividing T by you we take the current", "start": 1217.039, "duration": 5.551}, {"text": "state X and eval T takes the current", "start": 1219.38, "duration": 5.64}, {"text": "state X as an additional target the", "start": 1222.59, "duration": 4.89}, {"text": "input state what will we get back and a", "start": 1225.02, "duration": 5.61}, {"text": "white air a is the answer y is the new", "start": 1227.48, "duration": 6.24}, {"text": "tape takes the new state pass that into", "start": 1230.63, "duration": 7.2}, {"text": "eval of you get out the answer B and a", "start": 1233.72, "duration": 6.54}, {"text": "final state Zed and then our final state", "start": 1237.83, "duration": 4.44}, {"text": "for the whole thing is a divided by B", "start": 1240.26, "duration": 5.909}, {"text": "that's the answer and red plus one so", "start": 1242.27, "duration": 5.7}, {"text": "now we're incrementing the current state", "start": 1246.169, "duration": 6.421}, {"text": "and then if we execute eval of answer we", "start": 1247.97, "duration": 6.209}, {"text": "have to give it the initial state zero", "start": 1252.59, "duration": 4.56}, {"text": "and it returns the final state to as", "start": 1254.179, "duration": 6.661}, {"text": "well as the answer 42 okay", "start": 1257.15, "duration": 6.84}, {"text": "not clear enough to everybody so it's", "start": 1260.84, "duration": 8.18}, {"text": "easy but very very tedious", "start": 1263.99, "duration": 5.03}, {"text": "three I want to trace the execution of", "start": 1271.83, "duration": 7.06}, {"text": "my program so again normally I would", "start": 1274.72, "duration": 5.97}, {"text": "just write some output to the terminal", "start": 1278.89, "duration": 3.899}, {"text": "but I don't have writing output as a", "start": 1280.69, "duration": 3.989}, {"text": "side-effect so what shall I do", "start": 1282.789, "duration": 4.591}, {"text": "let's I think it's pretty easy let's", "start": 1284.679, "duration": 8.691}, {"text": "just rewrite the whole program so now a", "start": 1287.38, "duration": 8.7}, {"text": "computation that returns an A is going", "start": 1293.37, "duration": 4.779}, {"text": "to return some output paired with an A", "start": 1296.08, "duration": 6.69}, {"text": "and output will just be a string and so", "start": 1298.149, "duration": 6.51}, {"text": "to evaluate something it's going to", "start": 1302.77, "duration": 4.769}, {"text": "return an output integer pair match on s", "start": 1304.659, "duration": 5.64}, {"text": "again if it's a constant then return", "start": 1307.539, "duration": 4.951}, {"text": "some output saying I just evaluated a", "start": 1310.299, "duration": 4.11}, {"text": "constant and we can do that by saying", "start": 1312.49, "duration": 5.76}, {"text": "the line takes the term s and on the", "start": 1314.409, "duration": 7.171}, {"text": "answer a and it says so line takes a", "start": 1318.25, "duration": 6.69}, {"text": "term and an integer and replaces this", "start": 1321.58, "duration": 8.339}, {"text": "term equal sign the answer new line so", "start": 1324.94, "duration": 7.68}, {"text": "we place print that line or return that", "start": 1329.919, "duration": 5.191}, {"text": "line as output and return the answer a", "start": 1332.62, "duration": 5.64}, {"text": "and if we're doing a division so X's", "start": 1335.11, "duration": 6.15}, {"text": "will evaluate T X is the output a is the", "start": 1338.26, "duration": 6.899}, {"text": "answer will evaluate you Y is the output", "start": 1341.26, "duration": 6.09}, {"text": "B is the answer and then for the final", "start": 1345.159, "duration": 3.211}, {"text": "thing we'll place", "start": 1347.35, "duration": 3.39}, {"text": "print all the output from T all the", "start": 1348.37, "duration": 6.299}, {"text": "output from you a line saying astra", "start": 1350.74, "duration": 5.7}, {"text": "number S will be dipped to you I divided", "start": 1354.669, "duration": 4.23}, {"text": "T by you and the answer was a divided by", "start": 1356.44, "duration": 5.219}, {"text": "B and I'll return the answer a divided", "start": 1358.899, "duration": 7.921}, {"text": "by B okay clear enough right so at this", "start": 1361.659, "duration": 7.591}, {"text": "point hey you should all be nodding your", "start": 1366.82, "duration": 5.79}, {"text": "heads right and B you'd all be bored", "start": 1369.25, "duration": 5.309}, {"text": "silly and see somebody's actually asking", "start": 1372.61, "duration": 5.09}, {"text": "a question thank you yes", "start": 1374.559, "duration": 8.551}, {"text": "sorry I can't hear you why are we", "start": 1377.7, "duration": 8.17}, {"text": "calculating state and output so in this", "start": 1383.11, "duration": 4.799}, {"text": "case we were doing some state because we", "start": 1385.87, "duration": 3.36}, {"text": "wanted to count the number of division", "start": 1387.909, "duration": 3.51}, {"text": "operations you might have variant", "start": 1389.23, "duration": 3.689}, {"text": "recognize take they're better ways of", "start": 1391.419, "duration": 3.421}, {"text": "doing that than counting right I could", "start": 1392.919, "duration": 4.171}, {"text": "just have every operation return the", "start": 1394.84, "duration": 4.02}, {"text": "number of operations it did and then add", "start": 1397.09, "duration": 3.329}, {"text": "them all together that would be better", "start": 1398.86, "duration": 3.24}, {"text": "but I wanted something that involves", "start": 1400.419, "duration": 4.381}, {"text": "state so I did that because you", "start": 1402.1, "duration": 4.35}, {"text": "no of many computations where you do", "start": 1404.8, "duration": 3.42}, {"text": "need to pass state around a database a", "start": 1406.45, "duration": 4.2}, {"text": "and similarly sometimes you need to", "start": 1408.22, "duration": 3.66}, {"text": "trace things so that's why I'm doing", "start": 1410.65, "duration": 2.91}, {"text": "output here but again you'll think of", "start": 1411.88, "duration": 3.39}, {"text": "many things where you need to do output", "start": 1413.56, "duration": 3.21}, {"text": "or many things where you need to raise", "start": 1415.27, "duration": 3.75}, {"text": "exceptions so I've tried to take", "start": 1416.77, "duration": 4.14}, {"text": "examples so they're simple enough that", "start": 1419.02, "duration": 4.05}, {"text": "can cover them in a one-hour talk but", "start": 1420.91, "duration": 3.72}, {"text": "you will all be able to think of many", "start": 1423.07, "duration": 3.36}, {"text": "other things like this that you want to", "start": 1424.63, "duration": 5.25}, {"text": "do and you're nodding excellent thank", "start": 1426.43, "duration": 6.9}, {"text": "you okay but the point is by now you", "start": 1429.88, "duration": 5.73}, {"text": "should be bored okay yes I can do all of", "start": 1433.33, "duration": 4.35}, {"text": "these things yes the programs are", "start": 1435.61, "duration": 3.66}, {"text": "straightforward but they are very", "start": 1437.68, "duration": 4.5}, {"text": "tedious to write all right and let's", "start": 1439.27, "duration": 5.13}, {"text": "yeah so if we do Bell is out of answer", "start": 1442.18, "duration": 3.45}, {"text": "right we get the output well first I", "start": 1444.4, "duration": 4.77}, {"text": "evaluated in 1932 to 1932 then a value", "start": 1445.63, "duration": 7.28}, {"text": "80222 9 divided in 1932 by - that was", "start": 1449.17, "duration": 7.5}, {"text": "966 and I evaluate 23 to 23 and then the", "start": 1452.91, "duration": 6.4}, {"text": "whole expression evaluates to 42 and 42", "start": 1456.67, "duration": 5.88}, {"text": "is the answer okay so straightforward", "start": 1459.31, "duration": 7.14}, {"text": "but boring and tedious so here's what", "start": 1462.55, "duration": 5.37}, {"text": "we're going to do about the boring", "start": 1466.45, "duration": 2.85}, {"text": "tedious part right you'll recognize that", "start": 1467.92, "duration": 3.0}, {"text": "that slides they have this weird", "start": 1469.3, "duration": 3.09}, {"text": "background that's from the actual", "start": 1470.92, "duration": 7.68}, {"text": "original talk so what we're going to do", "start": 1472.39, "duration": 10.32}, {"text": "is define a monad back to the dictionary", "start": 1478.6, "duration": 8.97}, {"text": "known add now 1 be in the metaphysics of", "start": 1482.71, "duration": 7.98}, {"text": "line that's a simple indestructible", "start": 1487.57, "duration": 6.48}, {"text": "non-spatial element regarded as the unit", "start": 1490.69, "duration": 7.71}, {"text": "of which reality consists ok so you're", "start": 1494.05, "duration": 7.13}, {"text": "ready to see what that is", "start": 1498.4, "duration": 6.45}, {"text": "so it's just three things and remember", "start": 1501.18, "duration": 5.53}, {"text": "category theorist has this for", "start": 1504.85, "duration": 4.5}, {"text": "completely different reasons category", "start": 1506.71, "duration": 4.17}, {"text": "theorists were interested in problems in", "start": 1509.35, "duration": 4.53}, {"text": "algebraic topology of all things but for", "start": 1510.88, "duration": 4.89}, {"text": "that they needed this kind of structure", "start": 1513.88, "duration": 5.31}, {"text": "so it has three things number one for", "start": 1515.77, "duration": 6.99}, {"text": "each type a of values a type M of a to", "start": 1519.19, "duration": 5.28}, {"text": "represent computation so you probably", "start": 1522.76, "duration": 3.93}, {"text": "figured out what the Big M stands for", "start": 1524.47, "duration": 6.03}, {"text": "and in general what we're going to do", "start": 1526.69, "duration": 6.03}, {"text": "take a function from A to B and that's", "start": 1530.5, "duration": 4.26}, {"text": "going to become a function from A to M", "start": 1532.72, "duration": 6.29}, {"text": "of B that's the key idea", "start": 1534.76, "duration": 6.72}, {"text": "right and you've seen three examples of", "start": 1539.01, "duration": 4.63}, {"text": "that where we took eval which take", "start": 1541.48, "duration": 4.05}, {"text": "determine returns an integer and we've", "start": 1543.64, "duration": 3.81}, {"text": "turned it into eval which takes a term", "start": 1545.53, "duration": 5.46}, {"text": "and returns an M of integer and n is our", "start": 1547.45, "duration": 6.0}, {"text": "computation with computational effects", "start": 1550.99, "duration": 5.97}, {"text": "such as raising exceptions changing", "start": 1553.45, "duration": 7.02}, {"text": "state or printing output okay and then", "start": 1556.96, "duration": 6.81}, {"text": "we're going to need two things to go", "start": 1560.47, "duration": 5.79}, {"text": "with this first a way to turn values", "start": 1563.77, "duration": 4.74}, {"text": "into computations we're going to call", "start": 1566.26, "duration": 5.94}, {"text": "that pure so pure takes a value a of", "start": 1568.51, "duration": 6.66}, {"text": "type a and returns a value of type M of", "start": 1572.2, "duration": 4.83}, {"text": "a so this is the computation that", "start": 1575.17, "duration": 5.19}, {"text": "returns the answer little a of type big", "start": 1577.03, "duration": 6.75}, {"text": "a without doing anything else so it", "start": 1580.36, "duration": 6.0}, {"text": "leaves the state unchanged it raises no", "start": 1583.78, "duration": 6.08}, {"text": "exception or it prints no output and", "start": 1586.36, "duration": 5.81}, {"text": "then we need a way to combine", "start": 1589.86, "duration": 5.56}, {"text": "computations this is called bind and", "start": 1592.17, "duration": 6.1}, {"text": "this is the weird one so barn takes a", "start": 1595.42, "duration": 5.31}, {"text": "computation M that returns a value of", "start": 1598.27, "duration": 4.98}, {"text": "type a and now we want to do something", "start": 1600.73, "duration": 5.94}, {"text": "with that value of type a okay but we've", "start": 1603.25, "duration": 6.81}, {"text": "got something a type M of a and what we", "start": 1606.67, "duration": 4.38}, {"text": "want is something that does something", "start": 1610.06, "duration": 3.03}, {"text": "with V a so that's something that does", "start": 1611.05, "duration": 6.69}, {"text": "something with VA is called K which in", "start": 1613.09, "duration": 6.87}, {"text": "fact think of continuation that's why we", "start": 1617.74, "duration": 5.31}, {"text": "use K and the rest of the computation", "start": 1619.96, "duration": 6.69}, {"text": "the continuation takes the value a so", "start": 1623.05, "duration": 6.12}, {"text": "this is an a not an M of a and it", "start": 1626.65, "duration": 4.65}, {"text": "returns the computation of type B then", "start": 1629.17, "duration": 3.54}, {"text": "we put those together and the whole", "start": 1631.3, "duration": 5.58}, {"text": "thing is a computation of type B so in", "start": 1632.71, "duration": 6.42}, {"text": "language with side-effects this is just", "start": 1636.88, "duration": 7.2}, {"text": "a let expression evaluate m and then if", "start": 1639.13, "duration": 8.34}, {"text": "we wrote K is lambda X and it means bind", "start": 1644.08, "duration": 6.57}, {"text": "X to the value returned by M and then do", "start": 1647.47, "duration": 7.46}, {"text": "n so this would be let X equal m in N if", "start": 1650.65, "duration": 7.35}, {"text": "K was lambda X and then some expression", "start": 1654.93, "duration": 5.11}, {"text": "man so we'll see lots of examples", "start": 1658.0, "duration": 4.52}, {"text": "question", "start": 1660.04, "duration": 2.48}, {"text": "do I have a typo oh yeah there is a typo", "start": 1666.41, "duration": 12.04}, {"text": "thank you hey guys right so Toby we're", "start": 1673.38, "duration": 6.69}, {"text": "helping we do this and we must have it's", "start": 1678.45, "duration": 3.57}, {"text": "all running you can actually download it", "start": 1680.07, "duration": 3.6}, {"text": "from the web so we must have made an", "start": 1682.02, "duration": 3.18}, {"text": "error in typesetting it so this is", "start": 1683.67, "duration": 4.11}, {"text": "actually find of a comma B because both", "start": 1685.2, "duration": 5.58}, {"text": "a and B are types used by this thing and", "start": 1687.78, "duration": 5.91}, {"text": "the type inference system of Scala will", "start": 1690.78, "duration": 5.22}, {"text": "just infer a and B for you so we won't", "start": 1693.69, "duration": 7.02}, {"text": "need to write those all the time okay", "start": 1696.0, "duration": 7.14}, {"text": "and then these satisfy some laws this is", "start": 1700.71, "duration": 4.02}, {"text": "the only mathematics you'll see in the", "start": 1703.14, "duration": 4.38}, {"text": "talk and I'm not even going to go", "start": 1704.73, "duration": 4.26}, {"text": "through the details of how these work", "start": 1707.52, "duration": 4.05}, {"text": "but you're guaranteed that these if you", "start": 1708.99, "duration": 4.5}, {"text": "ever write that expression it's the same", "start": 1711.57, "duration": 3.57}, {"text": "as that one if you ever write that", "start": 1713.49, "duration": 3.57}, {"text": "expression it's the same as that one if", "start": 1715.14, "duration": 3.87}, {"text": "you ever write that expression it's the", "start": 1717.06, "duration": 4.5}, {"text": "same as that one and these happen to", "start": 1719.01, "duration": 5.79}, {"text": "look like the left unit right unit and", "start": 1721.56, "duration": 5.94}, {"text": "associative laws of a mono IDE okay", "start": 1724.8, "duration": 5.19}, {"text": "there's a scary word mono a it's the", "start": 1727.5, "duration": 4.95}, {"text": "name in mathematics for an operator and", "start": 1729.99, "duration": 5.94}, {"text": "a constant such that the constant is the", "start": 1732.45, "duration": 7.14}, {"text": "unit of the operator and the operator is", "start": 1735.93, "duration": 8.97}, {"text": "associative examples 0 and plus 1 and", "start": 1739.59, "duration": 13.89}, {"text": "times true and and false and or empty", "start": 1744.9, "duration": 10.92}, {"text": "string and string concatenation those", "start": 1753.48, "duration": 4.92}, {"text": "are all examples of mono 'its so if you", "start": 1755.82, "duration": 4.29}, {"text": "want to know where the name monad comes", "start": 1758.4, "duration": 5.1}, {"text": "from it's just a pun on mono I'd write", "start": 1760.11, "duration": 5.58}, {"text": "and category theorist or pretentious so", "start": 1763.5, "duration": 3.96}, {"text": "they like to adopt names from philosophy", "start": 1765.69, "duration": 4.5}, {"text": "which is why they use likenesses term", "start": 1767.46, "duration": 5.67}, {"text": "also used by other philosophers of monad", "start": 1770.19, "duration": 6.36}, {"text": "ok so now it's demystified where it", "start": 1773.13, "duration": 5.72}, {"text": "comes from", "start": 1776.55, "duration": 2.3}, {"text": "ok so now here's the payoff what happens", "start": 1779.6, "duration": 7.12}, {"text": "to our evaluator well we need more of", "start": 1783.78, "duration": 4.37}, {"text": "the definition of blown-out of course", "start": 1786.72, "duration": 5.49}, {"text": "monad noun 1 see in the pantheistic", "start": 1788.15, "duration": 6.96}, {"text": "philosophy of Giordano Bruno a", "start": 1792.21, "duration": 4.56}, {"text": "fundamental benefits", "start": 1795.11, "duration": 5.01}, {"text": "unit they did spatially extended and", "start": 1796.77, "duration": 9.24}, {"text": "psychically aware alright so what can we", "start": 1800.12, "duration": 10.3}, {"text": "do with our psychically aware monads so", "start": 1806.01, "duration": 6.12}, {"text": "will now go through and redo our", "start": 1810.42, "duration": 4.65}, {"text": "examples and see what had been tedious", "start": 1812.13, "duration": 6.0}, {"text": "and annoying becomes straightforward by", "start": 1815.07, "duration": 8.79}, {"text": "using a monad so first let's just look", "start": 1818.13, "duration": 7.62}, {"text": "at the simplest monads the one that does", "start": 1823.86, "duration": 6.14}, {"text": "nothing whatsoever the identity monad so", "start": 1825.75, "duration": 7.08}, {"text": "we'll just define an of a to be a a", "start": 1830.0, "duration": 4.929}, {"text": "computation that returns an a is just", "start": 1832.83, "duration": 4.26}, {"text": "the value of type a and nothing else", "start": 1834.929, "duration": 4.831}, {"text": "so what's pure do it does nothing it", "start": 1837.09, "duration": 4.98}, {"text": "just returns the a and what does bind do", "start": 1839.76, "duration": 4.56}, {"text": "well we're taking the same feeding it", "start": 1842.07, "duration": 3.75}, {"text": "indicate how will we do that", "start": 1844.32, "duration": 7.59}, {"text": "just apply k to a and then we can", "start": 1845.82, "duration": 9.87}, {"text": "rewrite our evaluator in this style so", "start": 1851.91, "duration": 5.91}, {"text": "again look at the term if it's a", "start": 1855.69, "duration": 4.619}, {"text": "constant now we need to return an M of a", "start": 1857.82, "duration": 7.44}, {"text": "so return pure of a right to bit as long", "start": 1860.309, "duration": 6.781}, {"text": "as you have any this works in any monad", "start": 1865.26, "duration": 3.9}, {"text": "whatsoever this works in the identity", "start": 1867.09, "duration": 3.93}, {"text": "monad and all the other monads that", "start": 1869.16, "duration": 3.87}, {"text": "we'll see so the point is we've now", "start": 1871.02, "duration": 4.409}, {"text": "generalize so that this piece of code", "start": 1873.03, "duration": 4.67}, {"text": "works for any kind of computation", "start": 1875.429, "duration": 5.341}, {"text": "whatsoever as long as it has a pure", "start": 1877.7, "duration": 5.59}, {"text": "operation and a bind operation and by", "start": 1880.77, "duration": 4.83}, {"text": "the way you can test those three laws to", "start": 1883.29, "duration": 4.889}, {"text": "see to have a sensible pure and bind", "start": 1885.6, "duration": 6.63}, {"text": "operation so if it's a constant do", "start": 1888.179, "duration": 9.571}, {"text": "nothing just return a so pure of a if", "start": 1892.23, "duration": 9.27}, {"text": "it's a division evaluate T this will be", "start": 1897.75, "duration": 7.95}, {"text": "an M of int and we want the integer a so", "start": 1901.5, "duration": 8.76}, {"text": "bind a to the answer from eval of T and", "start": 1905.7, "duration": 6.99}, {"text": "then evaluate you and bind B to the", "start": 1910.26, "duration": 5.52}, {"text": "answer of eval of you and then just", "start": 1912.69, "duration": 5.16}, {"text": "divide a by B and return to this pure", "start": 1915.78, "duration": 4.86}, {"text": "here is where types really get to be", "start": 1917.85, "duration": 5.94}, {"text": "your friend say that I omitted one of", "start": 1920.64, "duration": 6.15}, {"text": "those binds by mistake and just said let", "start": 1923.79, "duration": 6.45}, {"text": "a be the answer of this or or I admit", "start": 1926.79, "duration": 3.99}, {"text": "both", "start": 1930.24, "duration": 2.49}, {"text": "or I omitted the pure by mistake the", "start": 1930.78, "duration": 4.47}, {"text": "type checker will tell you this is", "start": 1932.73, "duration": 5.43}, {"text": "pretty much the only program that has", "start": 1935.25, "duration": 6.15}, {"text": "the right type right as long as we're", "start": 1938.16, "duration": 5.55}, {"text": "actually evaluating P evaluating you and", "start": 1941.4, "duration": 4.92}, {"text": "dividing the answers so the types get", "start": 1943.71, "duration": 4.35}, {"text": "all the mess of passing the monads", "start": 1946.32, "duration": 5.06}, {"text": "around they force you to get that right", "start": 1948.06, "duration": 5.55}, {"text": "right you could do something wrong you", "start": 1951.38, "duration": 5.8}, {"text": "can divide B by a instead of a by B but", "start": 1953.61, "duration": 6.21}, {"text": "the types force you to get the structure", "start": 1957.18, "duration": 5.37}, {"text": "of passing things around correct that is", "start": 1959.82, "duration": 8.64}, {"text": "where the types really help so now how", "start": 1962.55, "duration": 8.43}, {"text": "would we do exceptions so as before", "start": 1968.46, "duration": 5.79}, {"text": "we'll define M of a to be raised or", "start": 1970.98, "duration": 7.4}, {"text": "return and then pure is just return and", "start": 1974.25, "duration": 8.25}, {"text": "bind says well if we've gotten an ammo", "start": 1978.38, "duration": 7.39}, {"text": "type big M of a so we'll match it if", "start": 1982.5, "duration": 5.73}, {"text": "it's raised of e than just raising again", "start": 1985.77, "duration": 8.88}, {"text": "if it's return of a then we need to pass", "start": 1988.23, "duration": 8.51}, {"text": "this a in to the subsequent computation", "start": 1994.65, "duration": 4.71}, {"text": "which will return an M of B and that'll", "start": 1996.74, "duration": 4.03}, {"text": "be the type returned by the whole thing", "start": 1999.36, "duration": 4.5}, {"text": "so just apply K to a just as in the", "start": 2000.77, "duration": 8.25}, {"text": "identity mount app again this is pretty", "start": 2003.86, "duration": 7.77}, {"text": "much the only thing that has if you've", "start": 2009.02, "duration": 5.28}, {"text": "got that type and you know how M of a is", "start": 2011.63, "duration": 4.98}, {"text": "defined that's the only thing that has", "start": 2014.3, "duration": 5.28}, {"text": "that type Leonard Alderson has actually", "start": 2016.61, "duration": 5.13}, {"text": "written a program that given types gives", "start": 2019.58, "duration": 4.17}, {"text": "terms of that type it will return this", "start": 2021.74, "duration": 4.85}, {"text": "term so the type tells you what to do", "start": 2023.75, "duration": 5.4}, {"text": "and then finally there's one more thing", "start": 2026.59, "duration": 4.18}, {"text": "we need like you can think of this as an", "start": 2029.15, "duration": 5.13}, {"text": "abstract data type now and it's a monad", "start": 2030.77, "duration": 6.18}, {"text": "so it's got pure and vine and two monads", "start": 2034.28, "duration": 4.59}, {"text": "that can raise exceptions so it also has", "start": 2036.95, "duration": 6.06}, {"text": "a raise operator and what raise does is", "start": 2038.87, "duration": 5.64}, {"text": "of course given a string it just", "start": 2043.01, "duration": 3.78}, {"text": "returned so little our arrays just", "start": 2044.51, "duration": 6.03}, {"text": "invokes big are raised and that's all we", "start": 2046.79, "duration": 6.57}, {"text": "need like go back this is exactly the", "start": 2050.54, "duration": 5.16}, {"text": "same evaluator that we had before we", "start": 2053.36, "duration": 5.16}, {"text": "only need to change one bit which is", "start": 2055.7, "duration": 5.04}, {"text": "we've changed the answer before which is", "start": 2058.52, "duration": 4.77}, {"text": "pure of a divided by B but now it's if", "start": 2060.74, "duration": 3.09}, {"text": "the", "start": 2063.29, "duration": 4.11}, {"text": "zero raise / zero otherwise pure of a", "start": 2063.83, "duration": 6.54}, {"text": "divided by B and the rest is exactly the", "start": 2067.4, "duration": 5.19}, {"text": "same as before so now instead of having", "start": 2070.37, "duration": 5.1}, {"text": "to completely rewrite our evaluator we", "start": 2072.59, "duration": 6.65}, {"text": "just add the stuff we want", "start": 2075.47, "duration": 3.77}, {"text": "how about state again M of a is defined", "start": 2080.62, "duration": 7.81}, {"text": "as before it takes the old state and it", "start": 2084.89, "duration": 6.9}, {"text": "returns a value of type a paired with", "start": 2088.43, "duration": 6.45}, {"text": "the new state so pure does no", "start": 2091.79, "duration": 5.13}, {"text": "computation it just returns a value type", "start": 2094.88, "duration": 4.44}, {"text": "a so it takes the state and returns a", "start": 2096.92, "duration": 6.75}, {"text": "paired with the same state and that's", "start": 2099.32, "duration": 5.61}, {"text": "too hard to look at I'm going to do it", "start": 2103.67, "duration": 7.11}, {"text": "here and then bind it's going to return", "start": 2104.93, "duration": 8.25}, {"text": "in MFE so this must be something that", "start": 2110.78, "duration": 4.74}, {"text": "takes the initial state and returns B", "start": 2113.18, "duration": 4.77}, {"text": "and the new state so there's X that's", "start": 2115.52, "duration": 5.67}, {"text": "the initial State evaluate M applied to", "start": 2117.95, "duration": 5.88}, {"text": "X so we passed the old state into M we", "start": 2121.19, "duration": 4.85}, {"text": "get out the answer a and the new state Y", "start": 2123.83, "duration": 7.26}, {"text": "pass up like a to a that's the type M of", "start": 2126.04, "duration": 7.96}, {"text": "B is then expect the current state which", "start": 2131.09, "duration": 5.94}, {"text": "in this case will be Y and we get out", "start": 2134.0, "duration": 5.37}, {"text": "the final answer B paragraph said and", "start": 2137.03, "duration": 4.83}, {"text": "then we return a B's that pair notice I", "start": 2139.37, "duration": 3.81}, {"text": "could have written this more concisely", "start": 2141.86, "duration": 5.1}, {"text": "as just fell a y equals M of B and then", "start": 2143.18, "duration": 7.64}, {"text": "return K of a applied to Y and then", "start": 2146.96, "duration": 6.09}, {"text": "we'll need one more thing in this case", "start": 2150.82, "duration": 5.8}, {"text": "tik tik returns M of unit unit is the", "start": 2153.05, "duration": 5.49}, {"text": "type that has no interesting values in", "start": 2156.62, "duration": 3.51}, {"text": "it so the one uninteresting value of", "start": 2158.54, "duration": 3.96}, {"text": "type unit is written as the empty tuple", "start": 2160.13, "duration": 4.86}, {"text": "open parentheses close parentheses and M", "start": 2162.5, "duration": 6.3}, {"text": "of unit takes the input state returns no", "start": 2164.99, "duration": 5.73}, {"text": "interesting value and increments the", "start": 2168.8, "duration": 4.08}, {"text": "state by 1 so this is what changes the", "start": 2170.72, "duration": 5.88}, {"text": "state tik and in general for state monad", "start": 2172.88, "duration": 5.49}, {"text": "you might have an operation here that", "start": 2176.6, "duration": 3.45}, {"text": "changes the state however you want might", "start": 2178.37, "duration": 3.9}, {"text": "have get and set operations on the state", "start": 2180.05, "duration": 6.06}, {"text": "and then our dilator is just the same as", "start": 2182.27, "duration": 6.42}, {"text": "before we just change one line we put in", "start": 2186.11, "duration": 6.63}, {"text": "a tick before doing the division so now", "start": 2188.69, "duration": 5.52}, {"text": "we will count the number of division", "start": 2192.74, "duration": 3.62}, {"text": "operations", "start": 2194.21, "duration": 4.85}, {"text": "and write this program essentially is", "start": 2196.36, "duration": 4.98}, {"text": "just the one we saw before but we don't", "start": 2199.06, "duration": 4.19}, {"text": "need to rewrite everything tediously", "start": 2201.34, "duration": 4.5}, {"text": "like this is just the one we saw before", "start": 2203.25, "duration": 4.54}, {"text": "after you expand out all the binds and", "start": 2205.84, "duration": 4.05}, {"text": "the peers but you don't need to rewrite", "start": 2207.79, "duration": 5.49}, {"text": "everything tediously and finally for", "start": 2209.89, "duration": 7.14}, {"text": "output so MFA is now the output paired", "start": 2213.28, "duration": 6.57}, {"text": "with a pure obey is going to return an a", "start": 2217.03, "duration": 5.13}, {"text": "and no output so it's no output paired", "start": 2219.85, "duration": 5.48}, {"text": "with a bind", "start": 2222.16, "duration": 7.44}, {"text": "take some and add a decay again and what", "start": 2225.33, "duration": 5.95}, {"text": "are we going to do well M is going to", "start": 2229.6, "duration": 5.25}, {"text": "return output X and answer a we take K", "start": 2231.28, "duration": 6.15}, {"text": "apply to the answer a it will return", "start": 2234.85, "duration": 5.61}, {"text": "output Y and answer B and then we return", "start": 2237.43, "duration": 7.55}, {"text": "the append of x and y and the answer B", "start": 2240.46, "duration": 6.93}, {"text": "then we need one more operation again", "start": 2244.98, "duration": 5.98}, {"text": "output that takes a string and of course", "start": 2247.39, "duration": 5.94}, {"text": "it returns the string paired with a", "start": 2250.96, "duration": 4.62}, {"text": "value that's not of interest so it's an", "start": 2253.33, "duration": 7.08}, {"text": "M of unit any questions is that clear", "start": 2255.58, "duration": 5.07}, {"text": "enough", "start": 2260.41, "duration": 4.49}, {"text": "and again our program is just as before", "start": 2260.65, "duration": 6.42}, {"text": "except now we've got one more operation", "start": 2264.9, "duration": 4.69}, {"text": "we do an output of line si before", "start": 2267.07, "duration": 5.16}, {"text": "returning pure of a for con and we do an", "start": 2269.59, "duration": 4.95}, {"text": "output of line s and a divided by B", "start": 2272.23, "duration": 5.48}, {"text": "before returning pure of a and B and", "start": 2274.54, "duration": 5.82}, {"text": "again this simplifies just to what we", "start": 2277.71, "duration": 10.33}, {"text": "saw before that is it you are now expert", "start": 2280.36, "duration": 14.18}, {"text": "at monads any questions yes", "start": 2288.04, "duration": 6.5}, {"text": "am i implying that monads are exciting", "start": 2299.42, "duration": 6.669}, {"text": "because they give state output and", "start": 2303.18, "duration": 4.549}, {"text": "exceptions to functional languages", "start": 2306.089, "duration": 5.16}, {"text": "absolutely question the answer is sort", "start": 2307.729, "duration": 7.75}, {"text": "of yes they are exciting because they", "start": 2311.249, "duration": 6.48}, {"text": "give you those three things but they", "start": 2315.479, "duration": 4.951}, {"text": "also give you pretty much anything else", "start": 2317.729, "duration": 4.431}, {"text": "you can imagine", "start": 2320.43, "duration": 4.559}, {"text": "so in a language with side effects you", "start": 2322.16, "duration": 4.809}, {"text": "are limited to the side effects built", "start": 2324.989, "duration": 4.891}, {"text": "into the language but you can define a", "start": 2326.969, "duration": 5.55}, {"text": "monad for any of these three effects and", "start": 2329.88, "duration": 6.06}, {"text": "many many many others so you can have", "start": 2332.519, "duration": 5.79}, {"text": "monads to melt Matt to deal with", "start": 2335.94, "duration": 6.559}, {"text": "multiple answers lists of answers", "start": 2338.309, "duration": 7.41}, {"text": "streams of answers you have monads to", "start": 2342.499, "duration": 5.5}, {"text": "deal with concurrency so I'm not going", "start": 2345.719, "duration": 3.661}, {"text": "to go into all the different kinds of", "start": 2347.999, "duration": 3.391}, {"text": "images you can have you have monads to", "start": 2349.38, "duration": 4.649}, {"text": "deal with probability so you label each", "start": 2351.39, "duration": 5.31}, {"text": "answer with how likely it is so there", "start": 2354.029, "duration": 4.44}, {"text": "are all sorts of different things that", "start": 2356.7, "duration": 3.75}, {"text": "fall out of this among which are", "start": 2358.469, "duration": 5.3}, {"text": "included exceptions state and output", "start": 2360.45, "duration": 5.43}, {"text": "suggesting you to do exception state an", "start": 2363.769, "duration": 4.0}, {"text": "output that would be pretty cool but in", "start": 2365.88, "duration": 5.25}, {"text": "fact we can do so much more we can do a", "start": 2367.769, "duration": 5.49}, {"text": "huge variety of things and when I first", "start": 2371.13, "duration": 4.649}, {"text": "bumped in to monads I thought well gosh", "start": 2373.259, "duration": 4.171}, {"text": "it looks like you can do everything with", "start": 2375.779, "duration": 4.74}, {"text": "these why is that eventually we've found", "start": 2377.43, "duration": 4.5}, {"text": "some things that weren't lowness but a", "start": 2380.519, "duration": 3.871}, {"text": "huge variety of things can be done with", "start": 2381.93, "duration": 4.76}, {"text": "these and that's why they're so helpful", "start": 2384.39, "duration": 5.3}, {"text": "yes", "start": 2386.69, "duration": 3.0}, {"text": "couldn't you just hide monads under the", "start": 2391.039, "duration": 4.601}, {"text": "covers and have a normal language well", "start": 2393.39, "duration": 4.139}, {"text": "it's really helpful to know where you", "start": 2395.64, "duration": 3.719}, {"text": "have effects and where you don't and", "start": 2397.529, "duration": 4.26}, {"text": "that's why it's very useful but in fact", "start": 2399.359, "duration": 5.01}, {"text": "indeed it's a current active area of", "start": 2401.789, "duration": 4.591}, {"text": "research how do you build the monads", "start": 2404.369, "duration": 5.19}, {"text": "into the language and in fact remember I", "start": 2406.38, "duration": 5.099}, {"text": "said look what's awful about this is you", "start": 2409.559, "duration": 3.78}, {"text": "have to rewrite the whole program and", "start": 2411.479, "duration": 3.63}, {"text": "what's great about monads is you don't", "start": 2413.339, "duration": 3.66}, {"text": "but notice that when you move from not", "start": 2415.109, "duration": 3.66}, {"text": "being in a monad to being in a monad", "start": 2416.999, "duration": 4.26}, {"text": "then you do so once you have to rewrite", "start": 2418.769, "duration": 4.23}, {"text": "the whole program into tedious but", "start": 2421.259, "duration": 3.72}, {"text": "straightforward way and after that you", "start": 2422.999, "duration": 4.171}, {"text": "don't maybe the language could do that", "start": 2424.979, "duration": 4.02}, {"text": "rewriting force itself if we're in a", "start": 2427.17, "duration": 2.78}, {"text": "monad or not", "start": 2428.999, "duration": 3.141}, {"text": "so in fact there's that's an active", "start": 2429.95, "duration": 4.26}, {"text": "subject of research but it's not made it", "start": 2432.14, "duration": 4.07}, {"text": "into mainstream languages yet", "start": 2434.21, "duration": 5.159}, {"text": "good question thank you question at the", "start": 2436.21, "duration": 5.339}, {"text": "back", "start": 2439.369, "duration": 2.18}, {"text": "okay so the question was state and", "start": 2461.54, "duration": 7.87}, {"text": "output look very similar and I think", "start": 2466.04, "duration": 6.01}, {"text": "you're sort of noticing that if you", "start": 2469.41, "duration": 4.86}, {"text": "never use the IMP if you just use the", "start": 2472.05, "duration": 4.2}, {"text": "output operation go to current state", "start": 2474.27, "duration": 4.2}, {"text": "that comes in and you ignore it and you", "start": 2476.25, "duration": 4.59}, {"text": "send it to what sorry you take it and", "start": 2478.47, "duration": 3.9}, {"text": "you append to it what you want", "start": 2480.84, "duration": 3.69}, {"text": "so just appending things to the output", "start": 2482.37, "duration": 3.87}, {"text": "all of it to the current state all the", "start": 2484.53, "duration": 3.93}, {"text": "time that is just like output so you", "start": 2486.24, "duration": 4.38}, {"text": "could actually define output on top of", "start": 2488.46, "duration": 5.04}, {"text": "state that is true I just want to give", "start": 2490.62, "duration": 5.55}, {"text": "you three examples of a monad and in", "start": 2493.5, "duration": 5.37}, {"text": "fact when you define output the way it's", "start": 2496.17, "duration": 4.41}, {"text": "done you can see the two computations", "start": 2498.87, "duration": 3.48}, {"text": "are independent you could do them in", "start": 2500.58, "duration": 3.9}, {"text": "either order as long as you print the", "start": 2502.35, "duration": 3.48}, {"text": "output of the first one before the", "start": 2504.48, "duration": 3.15}, {"text": "output of the second one so there's less", "start": 2505.83, "duration": 4.83}, {"text": "time dependence and it's easy easier to", "start": 2507.63, "duration": 5.43}, {"text": "make parallel the stuff with output than", "start": 2510.66, "duration": 4.26}, {"text": "the stuff with state so that's one", "start": 2513.06, "duration": 3.15}, {"text": "reason why you might want to use output", "start": 2514.92, "duration": 3.9}, {"text": "rather than state because it's easier to", "start": 2516.21, "duration": 4.44}, {"text": "see the stuff works in parallel that", "start": 2518.82, "duration": 3.3}, {"text": "there's no dependence between the two", "start": 2520.65, "duration": 4.02}, {"text": "parts excellent question", "start": 2522.12, "duration": 6.0}, {"text": "thank you so I said you could use monads", "start": 2524.67, "duration": 5.85}, {"text": "to do so much more I'm at the end of my", "start": 2528.12, "duration": 4.29}, {"text": "time so I'm just going to wave this in", "start": 2530.52, "duration": 3.33}, {"text": "front of you and saying among other", "start": 2532.41, "duration": 3.44}, {"text": "things you can do lists and streams and", "start": 2533.85, "duration": 4.74}, {"text": "so bind is just the thing you need if", "start": 2535.85, "duration": 3.79}, {"text": "you want something like Cartesian", "start": 2538.59, "duration": 3.51}, {"text": "products so here MFA needs a list or a", "start": 2539.64, "duration": 5.46}, {"text": "stream of a and Emma fee is the same and", "start": 2542.1, "duration": 5.97}, {"text": "we want to return a list or stream of Av", "start": 2545.1, "duration": 7.02}, {"text": "pairs so we just bind em to a and bind n", "start": 2548.07, "duration": 7.53}, {"text": "to be and pure an a/v pair and by the", "start": 2552.12, "duration": 6.24}, {"text": "way that's just like a for loop for each", "start": 2555.6, "duration": 5.4}, {"text": "a drone from M and each be drawn from n", "start": 2558.36, "duration": 9.75}, {"text": "yield a paired with B and Scala supports", "start": 2561.0, "duration": 10.08}, {"text": "the special for syntax for dealing with", "start": 2568.11, "duration": 4.83}, {"text": "lists or streams or other collections", "start": 2571.08, "duration": 4.71}, {"text": "and it is just a monad it's built on top", "start": 2572.94, "duration": 5.49}, {"text": "of monads and that means the same for", "start": 2575.79, "duration": 4.5}, {"text": "yield notation we could have used it to", "start": 2578.43, "duration": 4.23}, {"text": "rewrite all the evaluators I showed you", "start": 2580.29, "duration": 5.37}, {"text": "so instead of saying you know following", "start": 2582.66, "duration": 6.93}, {"text": "eval of whatever to a da da we could", "start": 2585.66, "duration": 4.5}, {"text": "just say", "start": 2589.59, "duration": 4.86}, {"text": "for a drawing from em okay so there's", "start": 2590.16, "duration": 7.619}, {"text": "nice syntax that supports monads and", "start": 2594.45, "duration": 5.01}, {"text": "they are useful for all sorts of things", "start": 2597.779, "duration": 4.441}, {"text": "including pretty much the most important", "start": 2599.46, "duration": 7.26}, {"text": "data structure in the world the list not", "start": 2602.22, "duration": 5.76}, {"text": "to mention it works just the same with", "start": 2606.72, "duration": 3.27}, {"text": "the second most important data structure", "start": 2607.98, "duration": 6.69}, {"text": "in the world the stream so let's", "start": 2609.99, "duration": 6.99}, {"text": "conclude we're on to the second part of", "start": 2614.67, "duration": 4.74}, {"text": "the definition of bone app monad noun to", "start": 2616.98, "duration": 5.73}, {"text": "our single-celled organism especially a", "start": 2619.41, "duration": 8.099}, {"text": "flageolet protozoan so we actually use", "start": 2622.71, "duration": 7.71}, {"text": "monads in the Haskell compiler so the", "start": 2627.509, "duration": 4.921}, {"text": "very first Haskell compiler was written", "start": 2630.42, "duration": 4.47}, {"text": "in Haskell and each baised used a monad", "start": 2632.43, "duration": 5.609}, {"text": "so the type inference phase had a monad", "start": 2634.89, "duration": 5.04}, {"text": "that dealt with exceptions and state and", "start": 2638.039, "duration": 5.28}, {"text": "read only state so output is sort of", "start": 2639.93, "duration": 5.429}, {"text": "write only state", "start": 2643.319, "duration": 4.29}, {"text": "you also need read only say first things", "start": 2645.359, "duration": 3.601}, {"text": "like your current location at which you", "start": 2647.609, "duration": 3.45}, {"text": "want to report an error so for each", "start": 2648.96, "duration": 4.53}, {"text": "phase of the compiler there was an", "start": 2651.059, "duration": 4.74}, {"text": "appropriate monad to use and if you", "start": 2653.49, "duration": 4.41}, {"text": "decided you needed more stuff it was", "start": 2655.799, "duration": 4.201}, {"text": "easy to change the Mon app so this", "start": 2657.9, "duration": 4.83}, {"text": "actually worked in practice and my first", "start": 2660.0, "duration": 4.71}, {"text": "day to talk this was the only evidence I", "start": 2662.73, "duration": 4.5}, {"text": "had that monads were a good idea and now", "start": 2664.71, "duration": 4.109}, {"text": "people have used it in many many many", "start": 2667.23, "duration": 3.18}, {"text": "ways and there's a little bit more", "start": 2668.819, "duration": 5.371}, {"text": "evidence that they're a good idea so as", "start": 2670.41, "duration": 7.26}, {"text": "was mentioned they're not my idea the", "start": 2674.19, "duration": 7.53}, {"text": "Eugenio Margie's idea he wrote a paper", "start": 2677.67, "duration": 6.899}, {"text": "in 1989 he was interested in", "start": 2681.72, "duration": 4.649}, {"text": "denotational semantics of programming", "start": 2684.569, "duration": 4.47}, {"text": "languages a bit of mathematical theory", "start": 2686.369, "duration": 4.47}, {"text": "and he noticed that when you do", "start": 2689.039, "duration": 3.931}, {"text": "denotational semantics of things like", "start": 2690.839, "duration": 5.101}, {"text": "exception state and output you had to", "start": 2692.97, "duration": 5.16}, {"text": "tediously rewrite the entire semantics", "start": 2695.94, "duration": 4.139}, {"text": "and that monads gave a nice way of", "start": 2698.13, "duration": 3.75}, {"text": "structuring things so you didn't need to", "start": 2700.079, "duration": 4.351}, {"text": "do that and I read his paper I thought", "start": 2701.88, "duration": 6.12}, {"text": "hey that will probably work for writing", "start": 2704.43, "duration": 5.97}, {"text": "programs as well so that was my", "start": 2708.0, "duration": 4.92}, {"text": "contribution was to take this theory", "start": 2710.4, "duration": 4.59}, {"text": "done by a true category theorist Eugenio", "start": 2712.92, "duration": 5.07}, {"text": "and explain it to haskell hackers and", "start": 2714.99, "duration": 5.039}, {"text": "then from there it got out into all", "start": 2717.99, "duration": 4.879}, {"text": "these other languages", "start": 2720.029, "duration": 2.84}, {"text": "by the way Michael Spivey had also", "start": 2723.21, "duration": 4.62}, {"text": "noticed the utility of monads for", "start": 2726.21, "duration": 3.66}, {"text": "exception handling although he didn't", "start": 2727.83, "duration": 3.87}, {"text": "notice its utility for anything else and", "start": 2729.87, "duration": 5.85}, {"text": "ten years earlier John Reynolds in the", "start": 2731.7, "duration": 5.67}, {"text": "paper called the essence of elavil had", "start": 2735.72, "duration": 3.48}, {"text": "come up with this idea of separating the", "start": 2737.37, "duration": 4.71}, {"text": "type int and the type M event oh yes mo", "start": 2739.2, "duration": 4.74}, {"text": "jennie-o did mathematics so it wasn't", "start": 2742.08, "duration": 5.52}, {"text": "called damn it was called T yes that", "start": 2743.94, "duration": 5.61}, {"text": "really is how big the difference between", "start": 2747.6, "duration": 8.04}, {"text": "mathematics and programming is so John", "start": 2749.55, "duration": 9.18}, {"text": "Reynolds had this idea of a cut of data", "start": 2755.64, "duration": 5.79}, {"text": "types and what he called phrase types so", "start": 2758.73, "duration": 4.11}, {"text": "these are what we've been calling values", "start": 2761.43, "duration": 3.99}, {"text": "and computations and he had the same", "start": 2762.84, "duration": 6.51}, {"text": "idea that into X sorry into int in this", "start": 2765.42, "duration": 7.62}, {"text": "case would become int 2 into X but he", "start": 2769.35, "duration": 5.37}, {"text": "didn't have these idea of what we've", "start": 2773.04, "duration": 7.35}, {"text": "been calling pure and bind we're out of", "start": 2774.72, "duration": 7.41}, {"text": "definitions of monad we're on to the", "start": 2780.39, "duration": 3.6}, {"text": "next word in the dictionary which is", "start": 2782.13, "duration": 5.0}, {"text": "monad ism or Mona dolla G noun", "start": 2783.99, "duration": 5.28}, {"text": "especially in the writings of Leibniz", "start": 2787.13, "duration": 5.2}, {"text": "the philosophical doctrine that monads", "start": 2789.27, "duration": 8.94}, {"text": "are the ultimate units of reality and I", "start": 2792.33, "duration": 9.44}, {"text": "will stop there thank you", "start": 2798.21, "duration": 3.56}, {"text": "actually I won't stop there the two", "start": 2807.6, "duration": 4.03}, {"text": "other important things to do the first", "start": 2809.68, "duration": 5.88}, {"text": "yep the first is to thank my colleagues", "start": 2811.63, "duration": 6.48}, {"text": "Toni Morris and Jed Wesley Smith they", "start": 2815.56, "duration": 5.07}, {"text": "helped produce all this Scala yesterday", "start": 2818.11, "duration": 6.72}, {"text": "Jed's n types of it a masterful effort", "start": 2820.63, "duration": 6.72}, {"text": "and he put all the source available up", "start": 2824.83, "duration": 4.26}, {"text": "here so you can just go there if you", "start": 2827.35, "duration": 4.68}, {"text": "want to actually run this and then", "start": 2829.09, "duration": 5.04}, {"text": "there's one last thing which I have to", "start": 2832.03, "duration": 5.13}, {"text": "do which is to just remind you right", "start": 2834.13, "duration": 6.0}, {"text": "when you've got a tough job apply the", "start": 2837.16, "duration": 5.75}, {"text": "right mathematics that is your candle", "start": 2840.13, "duration": 5.28}, {"text": "when you've got to write a tough job", "start": 2842.91, "duration": 4.6}, {"text": "what you should think is this is a job", "start": 2845.41, "duration": 5.96}, {"text": "for lambda calculus", "start": 2847.51, "duration": 3.86}]]
so this is the first monad tutorial
these days there are lots of monad
tutorials for Scala or Perl or I think
that's channel 9 at Microsoft in the
bottom corner and one called yet another
presentation on loan ads and they have
all sorts of complicated diagrams in
them so you can point with this thing
going what have we got here
this is plumbing this is spacesuit this
is burritos and this is funny boxes with
balls in them but but remember that
symbol okay that symbol is important
right - you're all computer scientist so
you're not scared by funny looking
symbols right good actually we're quite
are you scared by funny-looking symbols
okay and you can get monads in all sorts
of languages so you've got Haskell just
go for your segments so this is very
colorful pointer writing people
sometimes get nervous but you don't need
to be nervous as long as you're
well-behaved and you can see the Haskell
logo actually has built into it this air
greater than greater than equal sign
which is the monad thing as well as
having a lambda built into it then we've
got closure f-sharp g-sharp Scala Python
we've already heard of Perl so there's
lots of languages that use these things
and a huge number of tutorials many of
them based on some weird kind of analogy
so here's the thing about this tutorial
it will contain zero analogies and you
might have heard that monads come from
category theory I have a colleague who
refers to category theory as
intellectual terrorism so if you've been
exposed to that kind of terrorism you
might be worried but don't worry you
need no category theory
whatsoever to understand this talk okay
all of you have the right background to
understand this talk so please if I say
something you don't understand raise
your hand and ask a question okay I
might accidentally forget to explain
something you should be able to follow
along if you can't please just ask a
question if you're embarrassed to ask a
question turn to the person next to you
and say he just makes it suitable I
don't know about puzzles you know about
Mosel and maybe they'll say oh yeah
whose lives of such and so but probably
they'll take no I don't know about foods
either and then you can raise your hand
and ask okay oh yeah and then we thought
of course all the means trapped in monad
tutorial please help
and the monad tutorials are coming and
here is monad man I thought oh this is
just something somebody found some
superhero with an M on their chest but
actually if you look down there you can
see he really wanted a is Katie
here.thank Katie for monad man a round
of applause for KD and monad man
and here's a graph of the amount of
known monad tutorials and this is just
for Haskell okay not any of the other
languages and you notice that in the
1990s it suddenly goes from zero to one
that's the one you're about to see so
here it is the first monad tutorial and
I need to say maybe just a little bit to
motivate why one would want a monad so
monads are there we go there's me and
I'm facing this tension so um to my
right there is a lambda sign how many
people recognize the lambda okay now all
of you do good you know so I thought
those nice silver one here that was made
for me as a gift by one of my students
so what lambda represents is the lambda
calculus and more importantly a nice
sound simple theoretical basis for
computing that has no side effects
whatsoever right normally when somebody
explains computing to you the first time
they say well there's a variable here
and that's a box and you put stuff in
the box and immediately you're often
analogies lambda calculus can be
explained very simply you have a term
and it's equal to another term which is
equal to another term and everything can
be explained by substituting equals for
equals and that's it so it's a wonderful
simple model of computing and that's
what we want to make use of now I know
not all of you are convinced by that
that's fine but you all will be right
this is how the world is moving right
twenty years ago nobody is using Haskell
these days it's used at major banks the
main - Haskell developers our time and
Peyton Jones in time and Marlowe
they were both at Microsoft Simon
Marlowe's just been hired away by
Facebook
lots of people these days are using
functional languages because when
there's no side effects the interface to
the function tells you everything there
is to know and that level of modularity
is really helpful in developing programs
okay so the great thing is it makes
everything completely obvious and that
gives you great structuring properties
and in particular these days when we
want to make things concurrent it's very
helpful because if something's making
use of assignment and of two concurrent
things making use of assignments you
have to worry about how those
assignments interleave right shared
memory is the root of all evil so if
you're in a pure functional language
there's no assignment it's much easier
to get things to work concurrently or in
parallel I'm not saying it's easy but
I'm saying that by not having to worry
about lots of assignment going on you
can focus on the real important problems
in making something concurrent ok so
functional programming there me with my
lambda everything is wonderful I'll show
you how wonderful right my daughter is
old enough it and she now makes stuffed
fuzzy toys to give to me rather than me
giving them to her this is the land that
she gave me okay and it's fuzzy I want
you to think about that right lenses are
fuzzy comfortable things but they're not
scary theory they are your friends you
want to cuddle up to them they want to
cuddle up to you okay so everything's
wonderful
so why on my other side am i plagued by
these three demons what are these three
demons so we've got the the up arrow of
exception raising the Kohen equal of
assignment the great evil and the curly
sheet of output and remember I said two
great
thing about pure functional programming
is it makes it completely obvious
everything that's going on but indeed it
can sometimes make things painfully
obvious right you have a lot of detail
in those cases where you actually do
need to pass around state and it does
happen right passing that around can get
a bit painful so there's things for
which sometimes you would think yep
exception handling is just the thing
outputs just the thing assignment is
just the thing and when you need them in
your in a pure language what you're
going to do not Ghostbusters monads okay
so that's what we're going to do so
you're ready to program we're actually
going to do some coding here are you
ready to code are you ready to code
let's see we'll skip over that from are
you ready to code in Haskell how about
are you ready to code in Scala
oh that's less maybe we should go back
to the Haskell talk right so I gave the
talk in Haskell last time and lots of
people hood and one reason they went is
perfectly reasonable which is rewrite
function application differently and I
even forgot to explain that clearly at
the beginning which is why you have to
all ask questions if you don't
understand I'm not going to blame myself
for not explaining nobody in the
audience asked who on them yeah no I
should have explained it's really my
fault but ask anyway so this time around
so that function application is written
in the style that looks more familiar
and I think that actually is very
helpful for audiences indeed my new
functional language length uses that
style of function application so we're
going to do it in Scala you can see it
in a more familiar way and long the way
we'll see some definitions of the word
monad so it actually monad noun 1
philosophy any fundamental entity
especially if autonomous on
sure that makes you feel much better
okay so there it is in Haskell and I
think there's one other thing that
really threw people which is like I said
it in an italic font so it looks all
pretty like mathematics and everybody
said Oh mathematics I am not worthy but
don't be afraid of mathematics right
mathematics is warm and fuzzy and cuddly
just like lambdas right are both not
many many years ago said if you have a
problem they're susceptible to
mathematics and you don't use it it is
as if you were in the dark and you
failed to light a candle mathematics is
your friend don't be afraid of it hey
you guys can all cope with JavaScript of
course you can do with deal with
mathematics okay
so here's some Scala and what we're
going to do is write out a very simple
evaluator for arithmetic as a way of
motivating why you might want monads and
so we just have terms and the term is
built in one of two ways it's either a
con for constant which contains an
integer or it's a div which contains two
other terms so these are going to be
parse trees representing arithmetic
problems built solely from constants and
division so for instance here's a term
that represents 1932 divided by 2 and
then you divide that by 23 okay and
here's another term that represents 1
divided by 0 nod if you're happy with
that most people are not nodding I'm
just going to stop right not if you are
happy with that
you're not nodding ask a question
I'll try a third time nod if you're
happy with that
you're still not nodding you really
better ask your question shouldn't the
type system stop you from dividing by
zero no so yesterday the Croft I
mentioned this theorem of Robin Millers
well hike programs don't go wrong but
wrong has a very specific definition in
the newspaper which you met forgot to
mention and the specific definition
basically means that something like
adding a number to a string that's wrong
trying to apply a number rather than
apply a function that's wrong but
dividing one by zero that's not wrong
that's bottom so we will catch certain
errors but not others so no the type
system doesn't prevent you from doing
every stupid thing just some stupid
things excellent question thank you
third time know if you're happy with
that all right that's enough naught so I
can move on
so now we'll write a little evaluator
writing it in Scala I'm not that useful
Scala so you guys can correct me if I
get anything wrong right so eat an
evaluator takes a term and it returns an
integer and we're going to match on that
term and there are two possibilities
right it's either a constant or division
if it's a constant just return that
constant if it's a division evaluate
both of the sub terms and then divide
the result okay pretty clear okay and
then of course if we set a to the result
evaluating answer that's a it always is
42 you did all that bill did that
division right why did I pick the 1932
so starting point by the way that's the
year in which lambda calculus was
invented
how many programming languages do you
know that were invented before there
were any computers lambda calculus is
cool okay and then of course if we try
to divide by zero then it's the computer
explodes right it gives us a divided by
zero error
we are going to do something about that
divide by zero error by the way more RAM
that won't help
so what are we going to do right what we
want if we're trying to divide by zero
we want to raise an exception so in the
language with side-effects that's easy
in a functional language it's also very
easy all you need to do is rewrite the
entire program so let's see how we would
rewrite the entire program so my
exception is going to be an error
message let's call make let's make those
strings and I'm going to find a type
called M of a so it's a parameterised
type the type is called m and takes a
type parameter which is an a what M of a
means is a computation that returns a
value of type a so in our case so and
what is M of a there are two
possibilities
it's either a raise of an exception so
string or its return of an A so right if
we return a value of type a we just
return it and otherwise we're going to
raise an exception so computation does
one of two things it raises an exception
that is it returns the string as an
error message or it returns a value of
type a so that's what M of a means in
this case see it's easy you just rewrite
the whole evaluator so what do we do
here um I'll just point at the string
rather than turning round can people see
that little hand yep okay so we've got s
which is a term and we match it right in
the two possibility if use a con or div
so if it's con of course we just return
a so notice now we have to write return
around a and notice that the good thing
about a type system is that you just
said a and you forgot the return the
type system would say did you really
mean that I don't think so and you'd put
in the return to give it the right type
which is in this case M event this works
right because a is an int so otherwise
it's a div of T nu and we're going to
we'll evaluate T of course T is going to
do one of two things it's either going
to give an error message if it does that
will just return that same error message
or
it's going to return some value let's
call it a and then the schools can
evaluate you and it'll do the same thing
if it gives an error message we'll
return it so I will raise it and if it
gives the value B well we'll check and
if B is 0 will give an error message
divided by 0 and otherwise we'll return
a over B so you said why doesn't the
type system get rid of you know tell me
that I'm dividing by 0 so it won't do
that but if you want to say well the
answer is either a value of type A or an
error message it will help you get that
right okay so all we had to do was
rewrite the program in this route
straight forward but revoltingly tedious
way let's try another possibility
oh no let's try it first let's just make
sure it works so let em be eval of
answer and n is going to be return of 42
but now if we do the dare err we get
raised of divided by 0 okay any
questions yet I had a question I've saw
this when I was working on it with Jed
and Toby we're very very helpful and
there will be a special thanks to them
at the end but I said why aren't there
quotation marks around four divided by
zero and they said well that's what
Scala does okay that's what scholar does
so let's look at a different thing to do
we want to count the number of division
operations so that's really easy if you
have global state you can just increment
the global state every time you do a
division operation but what if you don't
have state well that's really easy too
all we need to do is rewrite the entire
program so how are we going to do that
well now let's let's our state be an
integer the count of the number of
division operations and something of
type M of a is the computation that
updates the state and returns a value of
type a so it takes the current state as
input and it returns a pair of a the
answer whose type is a and the new state
so function from current state to
answer a new state so now eval is going
to take a term and return an M of int
and we'll match s and if it's a constant
then we don't change the state at all so
we take as input the state X and we
return an ax pair okay
take the input state return the answer
which is in this case a and return the
same state unchanged state doesn't
change no assignment okay so this arrow
here this is Scala's wave writing lambda
in lambda calculus you'd write lambda X
of type int returns and a X pair okay
not if you're happy you know what will
happen if you don't nod not if you're
happy you're not nodding ah you're
nodding imperceptibly okay we'll move on
any questions I'm not getting enough
questions here any questions okay
this is boring right it's easy to do but
it's boring it's tedious please
straightforward so if now if we're
dividing T by you we take the current
state X and eval T takes the current
state X as an additional target the
input state what will we get back and a
white air a is the answer y is the new
tape takes the new state pass that into
eval of you get out the answer B and a
final state Zed and then our final state
for the whole thing is a divided by B
that's the answer and red plus one so
now we're incrementing the current state
and then if we execute eval of answer we
have to give it the initial state zero
and it returns the final state to as
well as the answer 42 okay
not clear enough to everybody so it's
easy but very very tedious
three I want to trace the execution of
my program so again normally I would
just write some output to the terminal
but I don't have writing output as a
side-effect so what shall I do
let's I think it's pretty easy let's
just rewrite the whole program so now a
computation that returns an A is going
to return some output paired with an A
and output will just be a string and so
to evaluate something it's going to
return an output integer pair match on s
again if it's a constant then return
some output saying I just evaluated a
constant and we can do that by saying
the line takes the term s and on the
answer a and it says so line takes a
term and an integer and replaces this
term equal sign the answer new line so
we place print that line or return that
line as output and return the answer a
and if we're doing a division so X's
will evaluate T X is the output a is the
answer will evaluate you Y is the output
B is the answer and then for the final
thing we'll place
print all the output from T all the
output from you a line saying astra
number S will be dipped to you I divided
T by you and the answer was a divided by
B and I'll return the answer a divided
by B okay clear enough right so at this
point hey you should all be nodding your
heads right and B you'd all be bored
silly and see somebody's actually asking
a question thank you yes
sorry I can't hear you why are we
calculating state and output so in this
case we were doing some state because we
wanted to count the number of division
operations you might have variant
recognize take they're better ways of
doing that than counting right I could
just have every operation return the
number of operations it did and then add
them all together that would be better
but I wanted something that involves
state so I did that because you
no of many computations where you do
need to pass state around a database a
and similarly sometimes you need to
trace things so that's why I'm doing
output here but again you'll think of
many things where you need to do output
or many things where you need to raise
exceptions so I've tried to take
examples so they're simple enough that
can cover them in a one-hour talk but
you will all be able to think of many
other things like this that you want to
do and you're nodding excellent thank
you okay but the point is by now you
should be bored okay yes I can do all of
these things yes the programs are
straightforward but they are very
tedious to write all right and let's
yeah so if we do Bell is out of answer
right we get the output well first I
evaluated in 1932 to 1932 then a value
80222 9 divided in 1932 by - that was
966 and I evaluate 23 to 23 and then the
whole expression evaluates to 42 and 42
is the answer okay so straightforward
but boring and tedious so here's what
we're going to do about the boring
tedious part right you'll recognize that
that slides they have this weird
background that's from the actual
original talk so what we're going to do
is define a monad back to the dictionary
known add now 1 be in the metaphysics of
line that's a simple indestructible
non-spatial element regarded as the unit
of which reality consists ok so you're
ready to see what that is
so it's just three things and remember
category theorist has this for
completely different reasons category
theorists were interested in problems in
algebraic topology of all things but for
that they needed this kind of structure
so it has three things number one for
each type a of values a type M of a to
represent computation so you probably
figured out what the Big M stands for
and in general what we're going to do
take a function from A to B and that's
going to become a function from A to M
of B that's the key idea
right and you've seen three examples of
that where we took eval which take
determine returns an integer and we've
turned it into eval which takes a term
and returns an M of integer and n is our
computation with computational effects
such as raising exceptions changing
state or printing output okay and then
we're going to need two things to go
with this first a way to turn values
into computations we're going to call
that pure so pure takes a value a of
type a and returns a value of type M of
a so this is the computation that
returns the answer little a of type big
a without doing anything else so it
leaves the state unchanged it raises no
exception or it prints no output and
then we need a way to combine
computations this is called bind and
this is the weird one so barn takes a
computation M that returns a value of
type a and now we want to do something
with that value of type a okay but we've
got something a type M of a and what we
want is something that does something
with V a so that's something that does
something with VA is called K which in
fact think of continuation that's why we
use K and the rest of the computation
the continuation takes the value a so
this is an a not an M of a and it
returns the computation of type B then
we put those together and the whole
thing is a computation of type B so in
language with side-effects this is just
a let expression evaluate m and then if
we wrote K is lambda X and it means bind
X to the value returned by M and then do
n so this would be let X equal m in N if
K was lambda X and then some expression
man so we'll see lots of examples
question
do I have a typo oh yeah there is a typo
thank you hey guys right so Toby we're
helping we do this and we must have it's
all running you can actually download it
from the web so we must have made an
error in typesetting it so this is
actually find of a comma B because both
a and B are types used by this thing and
the type inference system of Scala will
just infer a and B for you so we won't
need to write those all the time okay
and then these satisfy some laws this is
the only mathematics you'll see in the
talk and I'm not even going to go
through the details of how these work
but you're guaranteed that these if you
ever write that expression it's the same
as that one if you ever write that
expression it's the same as that one if
you ever write that expression it's the
same as that one and these happen to
look like the left unit right unit and
associative laws of a mono IDE okay
there's a scary word mono a it's the
name in mathematics for an operator and
a constant such that the constant is the
unit of the operator and the operator is
associative examples 0 and plus 1 and
times true and and false and or empty
string and string concatenation those
are all examples of mono 'its so if you
want to know where the name monad comes
from it's just a pun on mono I'd write
and category theorist or pretentious so
they like to adopt names from philosophy
which is why they use likenesses term
also used by other philosophers of monad
ok so now it's demystified where it
comes from
ok so now here's the payoff what happens
to our evaluator well we need more of
the definition of blown-out of course
monad noun 1 see in the pantheistic
philosophy of Giordano Bruno a
fundamental benefits
unit they did spatially extended and
psychically aware alright so what can we
do with our psychically aware monads so
will now go through and redo our
examples and see what had been tedious
and annoying becomes straightforward by
using a monad so first let's just look
at the simplest monads the one that does
nothing whatsoever the identity monad so
we'll just define an of a to be a a
computation that returns an a is just
the value of type a and nothing else
so what's pure do it does nothing it
just returns the a and what does bind do
well we're taking the same feeding it
indicate how will we do that
just apply k to a and then we can
rewrite our evaluator in this style so
again look at the term if it's a
constant now we need to return an M of a
so return pure of a right to bit as long
as you have any this works in any monad
whatsoever this works in the identity
monad and all the other monads that
we'll see so the point is we've now
generalize so that this piece of code
works for any kind of computation
whatsoever as long as it has a pure
operation and a bind operation and by
the way you can test those three laws to
see to have a sensible pure and bind
operation so if it's a constant do
nothing just return a so pure of a if
it's a division evaluate T this will be
an M of int and we want the integer a so
bind a to the answer from eval of T and
then evaluate you and bind B to the
answer of eval of you and then just
divide a by B and return to this pure
here is where types really get to be
your friend say that I omitted one of
those binds by mistake and just said let
a be the answer of this or or I admit
both
or I omitted the pure by mistake the
type checker will tell you this is
pretty much the only program that has
the right type right as long as we're
actually evaluating P evaluating you and
dividing the answers so the types get
all the mess of passing the monads
around they force you to get that right
right you could do something wrong you
can divide B by a instead of a by B but
the types force you to get the structure
of passing things around correct that is
where the types really help so now how
would we do exceptions so as before
we'll define M of a to be raised or
return and then pure is just return and
bind says well if we've gotten an ammo
type big M of a so we'll match it if
it's raised of e than just raising again
if it's return of a then we need to pass
this a in to the subsequent computation
which will return an M of B and that'll
be the type returned by the whole thing
so just apply K to a just as in the
identity mount app again this is pretty
much the only thing that has if you've
got that type and you know how M of a is
defined that's the only thing that has
that type Leonard Alderson has actually
written a program that given types gives
terms of that type it will return this
term so the type tells you what to do
and then finally there's one more thing
we need like you can think of this as an
abstract data type now and it's a monad
so it's got pure and vine and two monads
that can raise exceptions so it also has
a raise operator and what raise does is
of course given a string it just
returned so little our arrays just
invokes big are raised and that's all we
need like go back this is exactly the
same evaluator that we had before we
only need to change one bit which is
we've changed the answer before which is
pure of a divided by B but now it's if
the
zero raise / zero otherwise pure of a
divided by B and the rest is exactly the
same as before so now instead of having
to completely rewrite our evaluator we
just add the stuff we want
how about state again M of a is defined
as before it takes the old state and it
returns a value of type a paired with
the new state so pure does no
computation it just returns a value type
a so it takes the state and returns a
paired with the same state and that's
too hard to look at I'm going to do it
here and then bind it's going to return
in MFE so this must be something that
takes the initial state and returns B
and the new state so there's X that's
the initial State evaluate M applied to
X so we passed the old state into M we
get out the answer a and the new state Y
pass up like a to a that's the type M of
B is then expect the current state which
in this case will be Y and we get out
the final answer B paragraph said and
then we return a B's that pair notice I
could have written this more concisely
as just fell a y equals M of B and then
return K of a applied to Y and then
we'll need one more thing in this case
tik tik returns M of unit unit is the
type that has no interesting values in
it so the one uninteresting value of
type unit is written as the empty tuple
open parentheses close parentheses and M
of unit takes the input state returns no
interesting value and increments the
state by 1 so this is what changes the
state tik and in general for state monad
you might have an operation here that
changes the state however you want might
have get and set operations on the state
and then our dilator is just the same as
before we just change one line we put in
a tick before doing the division so now
we will count the number of division
operations
and write this program essentially is
just the one we saw before but we don't
need to rewrite everything tediously
like this is just the one we saw before
after you expand out all the binds and
the peers but you don't need to rewrite
everything tediously and finally for
output so MFA is now the output paired
with a pure obey is going to return an a
and no output so it's no output paired
with a bind
take some and add a decay again and what
are we going to do well M is going to
return output X and answer a we take K
apply to the answer a it will return
output Y and answer B and then we return
the append of x and y and the answer B
then we need one more operation again
output that takes a string and of course
it returns the string paired with a
value that's not of interest so it's an
M of unit any questions is that clear
enough
and again our program is just as before
except now we've got one more operation
we do an output of line si before
returning pure of a for con and we do an
output of line s and a divided by B
before returning pure of a and B and
again this simplifies just to what we
saw before that is it you are now expert
at monads any questions yes
am i implying that monads are exciting
because they give state output and
exceptions to functional languages
absolutely question the answer is sort
of yes they are exciting because they
give you those three things but they
also give you pretty much anything else
you can imagine
so in a language with side effects you
are limited to the side effects built
into the language but you can define a
monad for any of these three effects and
many many many others so you can have
monads to melt Matt to deal with
multiple answers lists of answers
streams of answers you have monads to
deal with concurrency so I'm not going
to go into all the different kinds of
images you can have you have monads to
deal with probability so you label each
answer with how likely it is so there
are all sorts of different things that
fall out of this among which are
included exceptions state and output
suggesting you to do exception state an
output that would be pretty cool but in
fact we can do so much more we can do a
huge variety of things and when I first
bumped in to monads I thought well gosh
it looks like you can do everything with
these why is that eventually we've found
some things that weren't lowness but a
huge variety of things can be done with
these and that's why they're so helpful
yes
couldn't you just hide monads under the
covers and have a normal language well
it's really helpful to know where you
have effects and where you don't and
that's why it's very useful but in fact
indeed it's a current active area of
research how do you build the monads
into the language and in fact remember I
said look what's awful about this is you
have to rewrite the whole program and
what's great about monads is you don't
but notice that when you move from not
being in a monad to being in a monad
then you do so once you have to rewrite
the whole program into tedious but
straightforward way and after that you
don't maybe the language could do that
rewriting force itself if we're in a
monad or not
so in fact there's that's an active
subject of research but it's not made it
into mainstream languages yet
good question thank you question at the
back
okay so the question was state and
output look very similar and I think
you're sort of noticing that if you
never use the IMP if you just use the
output operation go to current state
that comes in and you ignore it and you
send it to what sorry you take it and
you append to it what you want
so just appending things to the output
all of it to the current state all the
time that is just like output so you
could actually define output on top of
state that is true I just want to give
you three examples of a monad and in
fact when you define output the way it's
done you can see the two computations
are independent you could do them in
either order as long as you print the
output of the first one before the
output of the second one so there's less
time dependence and it's easy easier to
make parallel the stuff with output than
the stuff with state so that's one
reason why you might want to use output
rather than state because it's easier to
see the stuff works in parallel that
there's no dependence between the two
parts excellent question
thank you so I said you could use monads
to do so much more I'm at the end of my
time so I'm just going to wave this in
front of you and saying among other
things you can do lists and streams and
so bind is just the thing you need if
you want something like Cartesian
products so here MFA needs a list or a
stream of a and Emma fee is the same and
we want to return a list or stream of Av
pairs so we just bind em to a and bind n
to be and pure an a/v pair and by the
way that's just like a for loop for each
a drone from M and each be drawn from n
yield a paired with B and Scala supports
the special for syntax for dealing with
lists or streams or other collections
and it is just a monad it's built on top
of monads and that means the same for
yield notation we could have used it to
rewrite all the evaluators I showed you
so instead of saying you know following
eval of whatever to a da da we could
just say
for a drawing from em okay so there's
nice syntax that supports monads and
they are useful for all sorts of things
including pretty much the most important
data structure in the world the list not
to mention it works just the same with
the second most important data structure
in the world the stream so let's
conclude we're on to the second part of
the definition of bone app monad noun to
our single-celled organism especially a
flageolet protozoan so we actually use
monads in the Haskell compiler so the
very first Haskell compiler was written
in Haskell and each baised used a monad
so the type inference phase had a monad
that dealt with exceptions and state and
read only state so output is sort of
write only state
you also need read only say first things
like your current location at which you
want to report an error so for each
phase of the compiler there was an
appropriate monad to use and if you
decided you needed more stuff it was
easy to change the Mon app so this
actually worked in practice and my first
day to talk this was the only evidence I
had that monads were a good idea and now
people have used it in many many many
ways and there's a little bit more
evidence that they're a good idea so as
was mentioned they're not my idea the
Eugenio Margie's idea he wrote a paper
in 1989 he was interested in
denotational semantics of programming
languages a bit of mathematical theory
and he noticed that when you do
denotational semantics of things like
exception state and output you had to
tediously rewrite the entire semantics
and that monads gave a nice way of
structuring things so you didn't need to
do that and I read his paper I thought
hey that will probably work for writing
programs as well so that was my
contribution was to take this theory
done by a true category theorist Eugenio
and explain it to haskell hackers and
then from there it got out into all
these other languages
by the way Michael Spivey had also
noticed the utility of monads for
exception handling although he didn't
notice its utility for anything else and
ten years earlier John Reynolds in the
paper called the essence of elavil had
come up with this idea of separating the
type int and the type M event oh yes mo
jennie-o did mathematics so it wasn't
called damn it was called T yes that
really is how big the difference between
mathematics and programming is so John
Reynolds had this idea of a cut of data
types and what he called phrase types so
these are what we've been calling values
and computations and he had the same
idea that into X sorry into int in this
case would become int 2 into X but he
didn't have these idea of what we've
been calling pure and bind we're out of
definitions of monad we're on to the
next word in the dictionary which is
monad ism or Mona dolla G noun
especially in the writings of Leibniz
the philosophical doctrine that monads
are the ultimate units of reality and I
will stop there thank you
actually I won't stop there the two
other important things to do the first
yep the first is to thank my colleagues
Toni Morris and Jed Wesley Smith they
helped produce all this Scala yesterday
Jed's n types of it a masterful effort
and he put all the source available up
here so you can just go there if you
want to actually run this and then
there's one last thing which I have to
do which is to just remind you right
when you've got a tough job apply the
right mathematics that is your candle
when you've got to write a tough job
what you should think is this is a job
for lambda calculus
(ns transcripts
(:require [cheshire.core :as json]))
(defn transcript [file-name]
(->>
(json/parse-string (slurp (str file-name ".json")))
first
(map #(get % "text"))
(interpose "\n")
(apply str)
(spit (str file-name ".txt"))))
(comment
(transcript "monads"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment