[MUSIC] There's just one more topic you need for Homework 3 and that's a little bit of guidance on how to find functions in ML standard library. So this doesn't really have a lot to do with the rest of the section other than the standard library does have a lot of useful and in good style high order functions. Well we decided to make it a small part of Homework3 because learning how, new programming languages and how to use them does involve learning how to find things in libraries. So ML like most programming languages has a standard library. This is just code that is always provided. in a particular way with any implementation of the language. I like to make this distinction that there are two sorts of things that you put in a standard library when you're designing your programming language. First, you put things that if you do not put them. Noone using your language, will be able to do things. If you don't give a way to open a file, on the computer the program is running on, you can't write code that will do it some other way. You need libraries for setting timers, libraries for accessing the network, libraries for printing things out. These are things that you can't build out of other pieces like lists and numbers and strength. The other thing you put in a standard library is actually optional relatively speaking. These are just things that are so common that having a standard definition is appropriate. Since ML programmers are going to use List.map, if we define it in the library, in 1 place, with 1 name, with 1 set of arguments in a particular order, then everyone can use it, and we can all read each others code more easily, and we don't all have to rewrite the same function for every program we're writing. So those are the two things one puts in a standard library. And as I mentioned, you should be comfortable in any language seeking out documentation and gaining some intuition on where to look. it doesn't make sense to always every time you need a function expect that someone like a course instructor will tell you exactly what function to use and where to look for it. For it. Okay. So standard ML has documentation for its standard library, it's actually quite a but more primitive than the documentation for most modern programming languages. But it will meet our needs, and it's at this URL you will see here. Here. Now, it's organized into things called structures and signatures. This is using ML's module system, which we're going to study just a little bit in the next section. But we can use the library before we really understand structures and signatures. And on homework 3 you just need to look things up in a few places. Things related to strings, characters so the char structure, lists, and they've separated out list pair. Those are functions that operate over two different lists. 'Kay, once you find something the way you use it is exactly like we have been using library functions already. Whatever structure it's in, you write the name of the structure then a dot, and then the function, so List.map, String.issubstring, or anything else. So I do have a web browser open here. This is the URL I've pointed you to, and there's a nice long list of things. There's functions for Arrays, some things for the Command Line. Some things for oh, INetSock is probably for accessing the network. One of the ones that we'll be interested in is the List structure where we have lots of stuff over lists. It gives a little synopsis of what this module is about. and then it lists all the different functions that are defined, just like the REPL would print them out. And the below that it has the actual documentation. Giving the documentation of the semantics of what these functions will do. So, for example, I never told you there is a function last, that takes a list l and returns last element of l. It raises a particular exception if the list is empty. And so on and so forth. Okay. So that's the documentation. There is no full substitute for proper written documentation about how a library should be used, in that form. But I wanted to point out one other thing. Which is, when you're programming with a REPL you can often save yourself a little bit of time by using the REPL to remind yourself some useful partial information about how things work. Like what functions are defined. what their types are what the order of arguments are. And today I'm going to show this I'm not showing you anything new feature of the REPL I'm just pointing out that you can use it for this purpose which you might not have thought of and it's so useful to do that that some REPLs have gone to the next step and they actually have added special commands that let you access the full documentation. For libraries written in the language, ML's REPL does not have that to my knowledge, so I just use it in sort of the way REPL's can always do, I just use it to look things up. So here's my REPL and I know that if I type, if I have a function defined like f n = x + 1, if I just type F. I say, oh, that's a function, and it's typed int arrow int. Well guess what? If I type List.map, it nicely reminds me the type of List.map. Oh, look. The 2 arguments are curried, not tupled. Maybe that's why I was getting an error message, so this is just a convenient thing to do. You can even guess, oh. List.last, was that, was that the name of the function? Oh, yes, it was. Right? You can kind of guess at function names if you want. if you think it's called fold left, it turns out you're wrong. You get and unbound variable that's not in the library. You're like, oh, is it called fold? No, it turns out it's called fold L. Now at some point you should stop guessing and messing around, and you should look up the documentation. But you know, this is fairly convenient. It turns out with one other trick, I'm not going to explain why this works, you can actually get the REPL to print out all the bindings. for a particular structure and once we know a little bit more about the module system this might make more sense. So for example, if you knew there was a list structure, and you just wanted to without going to your web browser look up everything, you can write the keyword structure, this is all ML code it's just features I haven't shown you. x = list And this is not very useful, it tells you that the signature, which is kind of the type of a structure is listed all capitals. And now if I say signature, spelled out English word, acts equals list. So I'm putting here whatever was after the colon on the previous line and hit return. While it prints out all that first part. Now I can't go that next step, I don't get that actual documentation but you might still find this useful. Anyway that's your brief guide to programming against libraries and that should be everything you need to complete Homework 3.