QuickBooks Online 2022, account and settings, expenses, payments, time and advanced tabs. Get ready because it's go time with QuickBooks Online 2022. Here we are in our Get Great Guitars practice file. We set up with a 30 day free trial here in the Get Things Done page, which used to be the home page holding control down, scrolling up just a bit to get to that one to five percent. At the preferences, which are in the cog up top generally, noting that when you're doing it normal day to day types of transactions, you're typically going to the plus button and or you're going to the centers on the left hand side. Also noting that the centers or activity or items on the left hand side could be in the business view currently, or you could have the accounting view, which you could switch to by going to the cog up top and switching to the accounting view. We're going to keep them at the business view at this time and go into the account and settings account and settings on the left hand side. We've been going through them on the left company bill and subscription usage sales. And now we're going to be down in the expenses area. So we have the bills and expenses. I'm going to click into it so we can drill down on it, show items, table on expenses and purchase forms. So the items table is going to be on by the default. It adds a product service tab on expense and purchase forms so you can itemize products and services. So when you're purchasing items, you're often thinking about inventory items. So these would be things that if you're dealing with inventory purchasing and selling the inventory, then you'd want the items tab typically there. So we could track the inventory units that are being purchased on the purchasing side of things with say an expense form, a bill form and the purchase order. So show tags, show tags field on the expenses and purchase forms. So the tags are that kind of specialty type of area that can give you an added level of tracking that could be useful in special kind of areas. We're not going to be talking about tags in the practice problem, but we might take a look at them after the practice problem in a bit more detail because they are an interesting tool. Track expenses and items by customer adds a customer feel as a customer column on expense and purchase forms. So you can track expense and items by customer. So in other words, when you enter like an expense form or a check, the things that decrease the checking account or bill like an expense type of form, then you might want the customer on it. Why would you want the customer on it? Because usually you would want the vendor on it, the person you're paying because you might want to add the customer to see who you're paying it for and possibly use it for a billable item, which is the next item, make expense and items billable adds a billable column to an expense and purchase form. So you can add so you can add billable expenses and items on the sales forms. So in other words, when you make an expense type of form, you might say that it's going to be a billable item. So it will then pull that item over into the invoice when you create an invoice for that particular customer. So in other words, you create for example, an expense form and you pay for the gas bill or something like that, the auto bill, you add the customer into the customer field, even though you're paying on the vendor side of things, money's going out. And then on the customer side, you add the customer field and you say it's billable, which means that when you then go into invoicing that customer, you could pull that information in. Now you've got to be careful about that because you've got to be careful about if you're not using the items properly, it might not record the invoice as revenue but as a negative expense like a reimbursement, which isn't exactly what you usually want to see. If you want to look at the items, we'll look at that more in future presentations. I'm going to keep it all for now and then we'll probably turn it on at some point in the practice problem and we'll note turning it on when we do so. Default bill pay terms, so the bill pay terms, let's default it to net 30, net 30. So that's going to be similar as to the receivable size. When we enter the bill, we're going to assume it's due in 30 days. Now the bills are a lot more tricky because when you have a receivable, you can set the standard date but when you get the bill from a vendor, you might not get it at the exact same date and so 30 days might not be the standard. That's why they don't really have a default standard. You might have to set the term date or the end date so that you could properly track when it's going to be due but I'm going to keep it at the net 30 here. We're going to save it and close it. Purchase order, so these are going to be the types of things that we're requesting inventory. They don't actually have a financial transactions to them and they would only be in there if you're dealing with inventory and you're in a situation where you can actually request the inventory without actually paying for it and then get the bill once we receive the inventory. So the purchase orders, we've got them on here so we're going to be using the purchase orders on by default and then custom fields go to settings list custom fields to manager custom field so we might have some custom items that we can add into the custom fields on the purchase orders. We're going to keep the default settings at the standard purchase order. Custom transaction number lets you use your own number system if left blank purchase order numbers are automatically assigned by QuickBooks. I'm going to keep them assigned by QuickBooks. We can also have a default message on the purchase order if we so choose. The message is down below. Default email sent with the purchase order so if we have the purchase order, if we're tracking inventory or purchasing and selling inventory and we send out the purchase order, this is another document that would be going to someone external this time to people we're buying from instead of people that we're selling to and we have the greeting that you could send with the email which would be the deer and then you've got the name format that you can go formal less formal and so on. Purchase order from Get Great Guitars is the subject line. Please find your purchase order attached to this email. Thank you Get Great Guitars, short and sweet. You can change it if you want though and then you can have a copy of the email going to you although that would probably if you have a lot of purchase orders be a lot of emails so typically most people might turn that off but it might be useful and that is that so let's go on to the payments area. QuickBooks online. Get paid more ways fast. They like saying that get paid. Get paid more ways fast. Take credit cards and bank transfer so these are other kind of payment options and you can look into whether or not these options would be right for you and they might be add-on types of features that you could look into. We're not going to turn them on for the practice problem. We might look into them again a little bit more after the practice problem but you can research them on the learn more here. Accept payments through QuickBooks, email, invoices, and mobile. QuickBooks automatically updates when you're paid and then you've got the existing account if you already have a payments account with Intuit you may know it as the go payment or merchant services. So then let's go to the time area. General first day of the week so we're going to say the first day of the week is Sunday for a seven day week as opposed to possibly Monday. The timesheets that you have show service fields which is when entering timesheets lets you specify services performed. So this is if you're using timesheets which you could use in order to help you track time for your employees and you can also use them to track time for billable time which you can then use to create invoices with. We'll take a look at these in a little bit more or timesheets when we do our practice problem allow time to be billable so that's going to be on timesheet as a checkbox to specify whether activities should be billed to the customer that's on by default that's a typical thing we're going to use it for and we'll test that out in our practice problem a little bit show billing rates on the user's entering time so if you bill customers a different hourly rate then you pay your employees in subcran tractors you may want to leave this blank so in other words you pay your employees you might pay them hourly but you might bill them out at a different rate most likely a higher rate than the which you pay them hourly or possibly you know it's what could be different so when you're using the timesheets to calculate the hours you might have a different hourly rate for the for the employee section versus when you're billing with an invoice okay let's go to the advanced tab we have the accounting up top uh first month of the fiscal year so it's we're looking first month not last month I used to look at these and always think well it's a December year-end thing and then you know you want to put December in there but they're asking for the first month which if it's a calendar year would be January first month of the tax year which could be different right the fiscal year tax year you could have a difference so we're going to keep it the same here however uh as the as the fiscal year the accounting method accrual I would keep that as the default unless your accountant specifically says otherwise you might say hey I'm on a cash basis method because I get paid at the same point in time that I do the work and I'm recording my stuff on a cash basis I don't have accounts receivable and accounts payable but you'll be able to track that generally by the fact that you're not using the accrual forms in other words instead of using an invoice form you'll be using a sales receipt form which is the cash basis form or you'll just be recording the income when you make the deposit and you will not be using a bill form if you're on a cash basis but just a check or expense form when you're making payments that's how you'll be on a cash or accrual basis so this will kind of change when QuickBooks possibly could recognize some income and again you don't really want to do that unless you have a specific reason to do that so I be very careful of changing that to a cash basis method you could still use a cash basis method by basically just entering data into the system in the format of a cash basis method but if you have to do an accrual thing it's usually good to be to have the capacity to do that so word of advice there talk to your accountant if you want to go to a cash basis close the books here we've got the close the close the books says when you're ready to close out the year close your books to prevent unwanted changes before filing your taxes this locks your books so no one can edit your accounting data before closing before closing date so in other words QuickBooks will automatically kind of close out the retained earnings the temporary accounts into the equity account the problem is that it's so flexible in adjusting prior transactions and prior periods that that people often go in and mess up the prior period transactions for something that had already been finalized and if that's the case then your retained earnings will not roll over from year to year so you can kind of close out the books here by toggling that on and then and then it says allow changes after viewing a warning and you could set the closing date so that's really a good thing to do especially if you have multiple people working in a file because you're basically saying don't mess up the prior year or don't mess it up you know don't do anything before this period you're gonna mess it up so you have unsafe changes do you want I'm not going to save any changes let's go to the next one company type they've asked us this a couple times and again I don't think it has a lot of difference on what's actually going to be in the tax in the actual software but you know the company the types would be because they're not changing like the retained earnings section or anything like that but in any case you want to choose the proper type of format of your company or your sole proprietor which typically means you report your your taxable income in the United States on the Schedule C one person for example partnership means you'll typically be reporting on a form 1065 for your taxes and then that will flow through to your individual partner 1040s if you have two or more people in like a partnership kind of situation then you've got the 1120S which is an S corporation which is another flow-through type of entity but it's set up as a corporation attempting to get the best of both worlds of a corporation liability protection and the flow-through of the S corp you might also have some tax benefit things with regards to payroll and what not but in the case we've got the corporation standard C corp this isn't a flow-through entity separate legal entity form 1120 non-profit of course form 990 limited liability company which is kind of like a partnership in general although you can make a single member LLC type of company and it's a flow-through type of entity as well and not sure here which i if you said not sure i don't think it'll change anything but you could probably pick the one that's applicable we're going to keep the sole proprietorship chart of accounts enable account numbers now the default is off for the account numbers which means that remember the chart of accounts is in order by in essence the ordering of the balance sheet on top of the income statement meaning assets liabilities inequity and then income or revenue and expenses and then sub-categories within that to get more detailed like bank accounts accounts receivable other current assets and so on if you wanted more detail within a certain section in terms of more control over it such as the expenses for example then you can turn on account numbers because if you don't it's going to then within the expenses category start to order it by alphabetical order or it'll order it also you have some control with the sub accounts but alphabetical order in general so you can turn account numbers on but you have to be careful with the account numbers if you want them we're not going to turn them on here we might talk about them later or after the practice problem because if you don't do the account numbers correctly and you don't know how to set them up then it's going to make things worse right it's going to make them more ugly and it's also takes a little bit more work so they keep them off by default tips tips account the account that goes with the setting sales sales form content and the tips so if you have tips that you're dealing with that might be applicable we've got the class tracking the locations tracking these are great tools they have like the tags and that they have a lot of different versatility depending on your different specialized needs i'm not going to turn them on here we might touch on them a little bit after the major practice problem adds a class field on forms so you can assign transactions to different segments like departments locations and products versus we have the location adds a location field on forms so you can assign transactions to different locations like stores sales regions and so on so these actually help you like make financial statements especially the income statement broken out by column to give you this different these different areas which is really a neat thing but we're not turning it on with the practice problem we're working in here automation prefill forms with previously entered content so automatically fills other fields of the form based on the last served transaction for the customer that's really useful because in the second month that we enter data we'll see that it'll be a lot easier to enter data because we will have automatically entered some of the transactions as we enter the vendors and the customers and then we've got automatically apply credits automatically applies credits to next invoice you create for the same customer most companies turn this setting turn this setting on turn it off if you if you if you're a property manager that requires a security deposit so if there's a credit then and then the next invoice we make it automatically applies to credit now they're saying and that's usually good so that means if we got a prepayment for example and we want to apply out the credit to an invoice we make later then it's nice that the system will do that automatically however you can imagine situations where that would be a problem such as a security deposit which means they are going to have a credit on the books all the time that supposedly you're going to get back at the end of the rental agreement which you know you never will anyways they're just going to say that there's something wrong with it and they'll take it but whatever they in theory they're supposed to give that back so in any case automatically invoice unbilled activity automatically creates invoices for customers with unbilled activities so it's off we're going to keep it off by default meaning if you if you put in time from the time sheets for example if it would automatically bill them or do you want to manually bill them it's might be better to do it manually because then you can actually kind of review the bills that are being created from the time when you put them together automatically apply bill payments when you add when you add bill payments in the register this set of setting automatically applies the payments to the oldest existing bills so it's similar that we saw on the on the receiving side of thing or the credit side of things we're going to then if you have a bill it's going to apply it to the to the oldest bill that's outstanding which would generally be what you'd want to do projects as a specialty area we're not going to deal with the projects in in depth here let's you see all your sales expenses and timesheet by project so that would be specific to a particular type of industry that you're using the projects to a great tool for specific types of things you might be using it for but we'll not focus on it and this practice problem home currency it's and we're using the united states dollar the general idea on the currencies would be that of course if you're outside of the united states the idea of the accounting is you're going to account for things in whatever the currency is so that's whatever currencies your currency that's what you're going to be using if you turn on multiple currencies then you're going to have a home currency and then if you have transactions to deal with other currencies it's going to have to denominate the other currencies in basically the home currency right we want all the financial statements to be measured with the tool the measuring tool of the home currency so we'll have the united states here if you have some other currency the accounting basically will work you know in essence the same it's just that it'll have a different a different currency so other other preferences a date format so here we're going to keep the default the month the day the year but you might be in an area where you prefer the date month year the date month year like this you might like the year first this is sometimes useful when you're when you're saving data because if it's an order by date you'd like the year first and then the month and then the day rather than the month and the year at the end so that could be a useful format but in the case number format we're going to keep this number format so if you have some other number formatting that is preferred you can do that and then we got the customer label the customer label clients customers donors now this obviously could be useful if you if you have some other type of business it's not a for like a non-profit so you could call them clients if you're a if you're a you know in a law firm or possibly CPA firm customers is the standard like and then donors if you're at a non-profit guests if you're in a in a some kind of something with real estate for example members patients and tenants so you can call them whatever is the appropriate name for the people that you're charging that are hopefully giving you money at some point so here it replaces the word customer wherever QuickBooks uses it in essence they're saying warn me when I enter a build number that's already used so that's going to be on warrant of duplicate check numbers is used so that's on it doesn't have this one on we'll keep it off by the default warrant of duplicate journal number is used we'll keep it off by the default sign me out if inactive four so if you're not using it for an hour it'll sign you out as a default mechanism and of course you can change those settings as well so those are going to be those items back to the home page i mean the get things done page


So we here at the ID Tech Act show here with EW panel and who are you? I'm Chunhua Yao. I'm from UW Madison, a PhD student now and also we are doing our own startup. So here we are showing the floor that can generate electricity. Can generate electricity? Yeah, so it's a very common floor. We got it from Home Depot and what's magic here is we embedded our nano generator inside and then when you tap it you can get... How? How is that possible? So we are using a triboelectric nano generator technology. It's very new. It was invented in 2012 and for this one you can use different materials to get the electricity for the specific application here. We use wood fibers. So this is vinyl. It's not real wood, right? This is wood. This is not the solid wood. It's called HDF highly density fiberboard. So this is for the floors that people have in every apartment, everywhere? Yeah, we got it from Home Depot. And how do you modify? Where do you put the modifications? So we embedded our stuff in this underlayment. We embedded our nano generator inside. So this part here is yours? No, this is also a very common one for flooring here, like for the water resistance. Okay. You put something in between? Yeah, we put something in between.  So how much energy is generated with this? So per step you can get several milliwatts and the voltage can be as high as 100 volts. So you would put all this maybe in the battery? We can store in the battery or capacitor or we can just use it directly. We are using this to directly power the LED. You don't need to store it. This is crazy. People will have their floors generate power. Right. And now we are actually talking with our university because it's based on our research. And so we are talking with our university. We want to do a demonstration. Like we are going to lay the floor of one room and then all on the hallway and then there will be a board saying oh today how many students pass and how much energy we have harvested. So is it easy to make the whole floor with this technology? It will be very easy because during our designing we already considered that we don't want to make too many too much changes to the standard flooring in the manufacturing. Is it possible that when you go to Home Depot you will buy this special floor with your technology inside? I hope in the near future. Near future, how far in the future? Next year? Yeah, at least one year I think. One year is not so much. And then after you connect this to the power or something charge the battery.  Yeah, also like in the backyard at night you just walk here and then you get the lights powered. So if there's not enough power you have to run and do exercise. But if you put this in the school or in the office there's hundreds of people. That's a lot of power. Also like on the stadium the fans are just so excited and jumping all the time. What is the competitor doing something similar? Some people are talking about doing this in a subway right? And there's a lot of people walking on the subway but they do use something completely different? They are using as I said they are using piezo material. So piezo material is expensive or like sometimes toxic. So for this one it's so environmentally friendly. And it's not so expensive cheap? No, it's cheap because it's made from wood fibers. Just from wood fibers? Yeah. But it's not as much power as piezo right? No, it's much the same comparable. Yeah, even like the voltage is even higher. It depends on what kind of piezo material you use. So when did you start to work on this? When was your idea to do this? We had, yeah so at the very beginning our research started like two years ago and then we patterned it and then we published the paper and then started this company. All right and this is a university of where? University of UW Madison, University of Wisconsin Medicine.


Hello everyone, I am Mrs. Sunita Do. Topic covered here is first set. In previous videos, we consider non-recursive predictive parser that has an input buffer, a stack, a passing table and an output string. Also, we consider how to pass the string of a given grammar using passing table. Now, the next task is to construct the passing table for which we need to compute two functions first set and the follow set. In this video, we are going to consider how to compute the first set for given grammar. Learning outcome. At the end of the session, students will be able to compute first set for a given grammar. The construction of a predictive parser is added by two functions associated with a grammar G. These functions are first and the follow set which allows us to fill in the entries of a predictive passing table for grammar G. If alpha is any string of grammar symbol, then first of alpha is a set of terminals that begin the string derived from alpha. If alpha derives epsilon in zero or more steps, then epsilon is also in the first of alpha. To compute first of x for all grammar symbol x, apply following rules until no more terminals or epsilon can be added to any first set. Rule number one, if x is a terminal, then first of x is x. If x derives epsilon is a production, then add epsilon to the first of x. And rule number three, if x is a non-terminal and capital X derives capital Y1, Y2 up to Yk is a production, then place small a in first of capital X. If first sum i small a is in first of capital Yi and epsilon is in all of first of capital Y1 and so on up to first of capital Y of i minus 1 that is capital Y1, Y2 up to Y of i minus 1 derives epsilon in zero or more steps. If epsilon is in first of capital Yj for j is equal to 1 to k, then add epsilon in first of capital X. So, we compute the first for any string capital Y1, Y2 up to Yn as add to the first of capital Y1, Y2 up to Yn on non-absolene symbol of first of capital Y1. Also add the non-absolene symbol of first of capital Y2, if epsilon is in first of capital Y1. The non-absolene symbol of first of capital Y3 if epsilon is in first of capital Y1 and first of capital Y2 and so on. Finally add epsilon to the first of capital Y1, Y2 up to Yn if for all i first of capital Yi contains epsilon. Consider the grammar for the arithmetic expression with the productions. Consider first production capital E derives capital TE dash. Here the right side of the production contains non-terminal capital T and E dash. Hence we apply rule number 3 to this production. So first of capital E is first of capital TE dash. We add to first of capital TE dash all non-absolent symbol of first of capital T and also we add the non-absolent symbol of first of capital E dash if epsilon is in first of capital T. Now first of capital T is first of capital FD dash so we add to first of capital FD dash all non-absolent symbol of first of capital F and also we add the non-absolent symbol of first of capital T dash if epsilon is in first of capital F. First of capital F is first of in parenthesis capital E and first of I D. First of in parenthesis capital E is left parenthesis and first of I D is I D as I D is terminal. Hence first of F is left parenthesis comma I D as the first of F does not contain epsilon. Hence the first of capital T is equal to first of capital F and also as the first of capital T does not contain epsilon. Hence the first of capital E is equal to first of capital T. Hence first of capital E is equal to first of capital T is equal to first of capital F equals to left parenthesis and ID. To compute the first of capital E dash, consider the production E dash derives plus capital T E dash or epsilon. First of capital E dash is first of plus capital T E dash and first of epsilon. First of plus capital T E dash is plus as plus is a terminal and first of epsilon is epsilon by rule 2. So first of capital E dash equals to plus comma epsilon. Now to compute the first of capital T dash, consider the production capital T dash derives star capital F D dash or epsilon. First of capital T dash is first of star capital F D dash and first of epsilon. First of star capital F D dash is star as star is a terminal and first of epsilon is epsilon. So first of capital T dash is star comma epsilon. Consider the second example of grammar with the productions capital S derives small i capital E small t capital S S dash or the small a that is on the right side of the production small i means if capital E means expression small t means then capital S means statement and capital S dash means statement dash so S derives if expression then statement L statement dash or small a. Capital S dash derives small e capital S or the epsilon that is S dash derives L statement or epsilon. Capital E derives small p. This grammar contains three non-terminal capital S capital S dash and capital E. Now consider the production capital S derives small i capital E small t capital S S dash or small e to compute first of capital S. First of capital S is first of small i capital E small t capital S S dash and first of small a.  So first of capital S is small i comma small a. Now consider the production capital S dash derives small e capital S or epsilon for first of capital S dash. First of capital S dash is first of small e capital S and first of epsilon. First of small e capital S is small e and first of epsilon is epsilon by rule 2. So first of capital S dash is small e comma epsilon. To compute first of E capital E consider the production capital E derives small b. Now the first of capital E is first of small b which is small b. So first of capital E is small b. Consider the third example of the grammar with the productions given on this slide. This grammar contains three non-terminal capital S A and B. Now consider the production capital S derives capital A small a capital A small b or capital B small b capital B small a to compute first of capital S. First of capital S is first of capital A small a capital A small b and first of capital B small b capital B small a. So we add to the first of capital A small a capital A small b all the non-absolence symbol of first of capital A and also we add non-absolence symbol of first of small a if epsilon is in first of capital A and so on. First of capital A is epsilon by rule 2. As the first of capital A contains epsilon we find first of small a which is small a. As the first of small a does not contain epsilon so now we do not add anything to the first of capital A small a capital A small b and also we do not add epsilon to the first of capital A small a capital A small b.  Similarly first of capital B small b capital B small a is small b. Hence the first of capital S is small a small b. To compute the first of capital A consider the production A derives epsilon. First of capital A is epsilon by rule 2. Similarly, to compute the first of capital B consider the production capital B derives epsilon. The first of capital B is epsilon. Till now we consider how to compute the first set for the terminal as well as non-terminal. Now pause this video and reflect on this question for a minute or two minutes and write your response. Once you have written the answer to this question then you can restart playing this video. The question is compute first set for the following grammar. I hope all of you have completed this activity. Now consider how to compute the first set for this grammar. This grammar contains non-terminal capital S and the C. To compute the first of capital S consider the production capital S derives capital C C. First of capital S is first of capital C C and first of capital C C is first of first capital C and first of second capital C if first of first capital C contains epsilon. To compute the first of capital C consider the production capital C derives small c capital C or small d. First of capital C is a first of small c capital C and first of small d. First of small c capital C is small c and first of small d is small d. Hence first of first capital C is small c comma small d. As first of first capital C does not contain epsilon hence the first of capital S is first of first capital C which is small c comma small d. This is the reference used for preparing this presentation. Thank you.


For the Facebook and Instagram ad audience, there is a strange discovery that some of us have found, which is that the audience app database is slightly different in terms of whom you can target. So let me go ahead and share my screen and I'll show you what I mean by this. Like I'm in my Facebook ads manager audiences tool. I'm not gonna go from the start of this because I'm just talking about this issue here. So when you're creating an audience in Facebook ads manager, right? This hopefully looks familiar and you use detailed targeting. And so for example, and I wanna thank Joe Miller for alerting me to this strange, you know, discrepancy. She was trying to target people interested in embodiment or somatic therapy. And so she started typing in embodiment. And of course I start typing it in and there is no embodiment here, right? There's embroidery, embrace, embellishment. I start typing in EMBO, nothing. All right, how about another one? How about somatic? Okay, somatic therapy, nothing. Also Grace Yang also alerted me to a couple of others. HSP, you know, highly sensitive people. Can't target that here. What about empathy or empathic? Empathic empathy? No, nothing, empanada, delicious. But empathic, nothing. All right, now let me go ahead and show you Instagram. Okay, so I'm gonna go and show you my screen. Okay, so say hello to buddy, my dog. All right, let's go to Instagram and I'm on my profile. If I just go to my recent post and I click on boost post, let me show you the difference here. Okay, so here in boost post, I'm just gonna pretend I'm doing an Instagram ad. I'm not gonna go through with it, but I just wanna show you the audience. I'm gonna create a new audience. Create your own at the bottom, bottom, okay? All right, I'm not gonna worry about locations or age and gender right now. I'm gonna go to interests, right there in the middle. And I'm gonna type in embody, body. Okay, why is it not working? Okay, of course, now that I'm trying to show you, it's not working. But embodiment, maybe they've already removed it, but it was available earlier. Let me see somatic, at least somatics is available. So somatic, somatic psychology, those were not available in Facebook ads manager. What about HSP, Highly Sensitive People? There we go, HSP. Now, how do we know that HSP here means Highly Sensitive People? It's a very good question. Let's click on it. Okay, once we click on it, click on it. Now, it gives suggested interests, personal development. Because personal development apparently is connected to HSP. Now, let's try another one that wasn't available in the other one, empathy, I think. Empathy, right? Empanada was available, but not empathy. So there are somehow, and the question is, well, George, how do you find out these ones that are available here, but not there? I guess it's by chance. I don't know if somebody out there on Google has made some kind of a study of this and made a list. I haven't researched it, but basically these came from some of my Facebook ad students discovering this. So I hope this is helpful. And basically the question for you is, well, should you then use the Instagram boost post thing to reach certain interests that you can't reach on Facebook ads? Well, the drawback of Instagram boosting the post is that you can't exclude your warm audience. So those of us who are doing a more sophisticated strategy of separating warm and cool audiences, like, okay, I'm just gonna run ads to cool, I'm gonna run some ads to warm, and then the cool audience is gonna separate the warm so that I can get better data about who's actually liking my stuff. Because if you run an ad on Instagram, empathy, HSP or whatever, and then you get the people liking your post, how do you know who was in your warm audience and who was in the cool audience? You don't, you don't know. So for audience testing, this Instagram thing doesn't work. But if you just wanna do a very, you wanna use it as a blunt instrument, a very just broad, like I don't care about testing audiences, I just wanna reach some people, then apparently the Instagram database allows you some additional interests. So I hope this helps. And thanks Colleen for asking. Yes, you can only do the boost post for Instagram on the mobile. And now you might say, George, I know that if I boost post on Instagram, it still shows up in my Facebook ads manager, can I then edit it there for further precision? Last time I tried, I can't. Now you could try it because somehow when I boost post here and then I go in and try to edit. In fact, let me see if I can show you an example. When I try to edit, it's been a while since I've boosted a post on the Instagram mobile. So I don't know if it's different now, but let me see if I can find one. Let me see if I can find one. Instagram post, I think this was a boost. Okay. Okay. Was this a boost? See? Yes, this was a boost. See, I go to the ad set level and says this ad set was created on Instagram and cannot be edited here. Open your Instagram app to edit the original. You see? So I can't do the precision. Now, if I go to the third level, see? I can't even edit the, I can't edit the ad. I cannot edit the ad set. All I can do is edit the campaign. I can, I guess I can edit the budget a little, maybe. I'm not sure because if the ad set doesn't have some people sometimes the ad budget anyway, long story short is, yes, what we just show, I just wanted to show you on my mobile phone can only be done on the mobile with a boost post, but then you can't further make it more precise on the Facebook ads manager. So.


Okay, so two announcements. Today is the first feedback session on your final project. So we'll move back to Soda and the first 10 teams will meet with me 5 to 15 to 6 to 15. There are some really exciting proposals. I look forward to talking with you. The next announcement, again, it's Tuesday, so the next project assignment is out. This one should be fun. It's a culmination of the parser part and the compilation part, so you will write a few little languages. Essentially, putting together everything you build so far. What we'll do today is look at another family of statically typed languages. Last time we looked at Java, and what static type checks you do during compilation on the program. How you delay some of the checks to run time so that the type checker isn't too strict and doesn't reject programs that might actually very well be correct. And the Java type system is fine in that it does give you not only a sense of documentation about your programs, but it does give you a lot of strong type properties, type checks at compile time. You know that certain things will not crash when you run the program. For example, what are the things that are guaranteed not to cause you troubles once you run the program? In a Java program versus, say, a Python program or a JavaScript program. One example of that. In an object, it's guaranteed that when you access an object, it is going to have that instance variable. But you cannot guarantee in Java, for example, that it is not now. That runtime error you still can have. What are some of the other things that are guaranteed not to? Buffer overflows, but those are guaranteed also in Python not to happen. So in that sense, Java doesn't give you any stricter guarantees. Those in Java are delayed till runtime might as well. Some other things that Java checks at compile time? Exactly. So the arity of functions and the types of arguments to functions for that reason as well. And also because it knows what types these are, the compilation can be better. The objects don't need to be hash tables, associated arrays, in other words. But they can be structs like in C, the way you learn, presumably, in 61B. But you'll plug in. But Java is not the end of the evolution of programming languages. And in fact, new statically-typed programming languages like Scala and evolution of Java are inspired by ML, a language that uses static types but uses them differently. And so what we'll try to do today is essentially reinvent a little bit about ML. We sort of succeeded reinventing parsing by looking at the fundamentals, what the grammars are, and building a parser in prologue, and then reinventing C, Y, K, and then optimizing it in early. So we did sort of from basic principles quite a bit of history of computer science. So today we'll do a little bit about ML. So the way we'll start is well, actually. Let me tell you what happened in Java, that in Java you actually name the types of the parameters. But why would we do it if we can infer those types automatically without these annotations? So let's start with this factorial program. It's essentially written in the 164 language. And could you actually look at that and see what is the type of the function, what arguments it accepts, what type of arguments it accepts, and what types of values it returns? It accepts some sort of a number. How do you know it's a number? So here is the argument, and we apply multiplication on that number. So there is another operation on n. So n definitely will be a type that supports multiplication and subtraction. So we know that much about the parameter of the function. What do we know about the return value? So that's another operation. So what we know about n is that it needs to support equality, multiplication, subtraction. So the return type must be either one or the result of the multiplication. These are the return values. So the reasoning that you've done is correct. So the argument could be anything that supports equality, subtraction, multiplication. And the return value is the type of one, and it must be something that does multiplication. And so reasoning about this manually is fine. But when the programs grow big, think 100,000 lines of code, that sort of reasoning might be problematic. So we want an algorithm for doing this type inference for us. So I'll erase all these reasoning. Let's now think how we would actually build a type inferencer which simultaneously type checks the program. How would we build it for programs of that sort? So what are those programs? Imagine that these are 164 programs that support dynamic types. The value carried their types at runtime with them in a sort of tag, as is the case in our interpreter. But now I want to optimize them or type check them for errors at compile time. So what would that algorithm be? So Elbon, I'll let you think a little about what the algorithm would use to do this type inference. And could we use tools that we have already developed in the course to figure out all these types? I know you know the answer. I would like others to participate. I'm sure they are almost ready to raise their hand. OK? So I like the algorithm because it is very simple and often it actually works. What you are saying that I have a function which we denote this way. It's a function from some type that we need to fill in into this box into some type. The arrow signifies a function type, something that gets a function from one argument to one return value. And you're proposing to let's go through all the types that we have in the system. And essentially all pairs because we need to pick a type for the argument and for the return value and enumerate all of them, see for which the function type checks, and we are done. So that in principle would work. It would probably be even reasonably efficient, but we want something more efficient than that. But even efficiency aside, there is a problem with that. What could be the problem with this approach? One is enumeration of the set of types. Not just inefficient, but in fact impassive. The programmer can define their own types. And yeah, maybe you can discover them from the source code of the program. So maybe that would not really be a problem. But even if you could find all the user-defined types, even then there could be a problem. What obstacle do you see to this algorithm? So the algorithm again is to create a list of all our types. Now you create a list of pairs for all possible types, run them through the type checker and see which of them check up. What could go wrong? Is it guaranteed that the set of types we might see in the program is bounded by some number, or could we create an unbounded number of types? How about if we have a list of pairs, such that the first pair is a list of pairs of ins, and the second element of the pair is a list of pairs of lists. See how you could create, in Python, essentially infinitely many different types. Because you can, in your program, use data structures of arbitrarily deep nesting. Then the type checker could not just enumerate all of them because you would never know that you have enumerated enough. And it would not be probably efficient to try types that go, I don't know, 1,000 deep because, of course, there are just too many of them. OK, so that's a good idea. Indeed, we'll use prologue. And we can think of it as sort of solving some constraints of types. But what we'll do, well, maybe somebody can suggest now how to do it in prologue. So prologue is the idea that we'll take a program, we translate it into a prologue program, whose sole purpose is not to evaluate this, not to act as a factorial, but just compute those types. And so that prologue program will be our type inferencer. When you run it, it computes these types for us. OK, so what you're essentially proposing is to turn this program into its abstract syntax tree, which we know how to do, and propagate some information up. Now, what if that could be done, of course, without any prologue machinery? We just propagate this. Well, is it guaranteed that as we go bottom up on the abstract syntax tree that we always, when we reach a node, know the types of all the variables down there in the subtree? Not necessarily, right? Because sometimes you need to know the constraints from up there. For example, in this case, perhaps you know. But if I give you another program, which has some conditional, and here you return 1, and then you return n, if you look at this program, can you tell the type of n? Can you tell the type of n by looking at this red program? You cannot. Well, so it really now depends how flexible we want to be. But the reasoning we'll use is that this expression here could return what value here? An integer, right? And so we'll adopt a rule that both sides of this if must return the same type. And so you see, because this is one, the other one must be one as well. So if you look at this if statement or if expression, if this is one and this is n, then this is int. And this is also int for the reason that the left side of the if is int. So this one here constrains this n as well.  But at this point, you don't know yet the type of n. It's only when these two subtrees emerge together. Exactly. But we need to accept the fact that some information, some constraints essentially will be flowing that way. We cannot compute everything going bottom up. We can merge them, but the computation of those constraints will happen up there in the if. It's not a problem, but it's not a problem. Except what you are computing by the bottom up propagation is not actually the types of things, but a prolog program, which when you run after you compute everything, you'll get a type. So let's go through an example here. Yes? Well, OK, that's an excellent question. What if the else does not return the same type? What if we have written a program in which the if returns one and then returns something else, the function foo might return a string, right? We don't know. So if it indeed foo could return a string, then the type checker would say, I cannot type the program. I cannot prove that indeed both the then branch and the else branch return an int. And what the type checker will do? It will reject the program as one that is not type safe. So this is an example of how some programs that would be correct in the dynamically type setting, Python, JavaScript, and run correctly without an error would be rejected by the type checker because the type checker does not know everything about the program and it does more conservative, more myopic, local reasoning. And therefore, good programs are rejected. That's the price you pay for getting some guarantees at compile time before running the program. Not always good trade-off, but often when you are putting the program on a spaceship that's going to fly to Mars, you might want to have a guarantee that something won't go wrong halfway. And yes, the program or productivity might be a cost here, but programs typically are more reliable than they are statically typed. So again, we make the assumption that the type of that must be the same because they will flow into the same, you could say, port of the function, the return port. OK, so we are here. We know that we are going to take the program and translate it into a prologue program which when we run, you'll get the types out. Could you suggest an approach for doing this? So let's brainstorm here. I want us to understand it by discovering it from first principles. So the prologue program will presumably have some variables, those things with capital letters to which we assign values by running the prologue program. The prologue program essentially solves for the values of those prologue variables. What will be the values of those prologue variables?  What will be the domain of those values for the prologue variables? It will be types. So we'll invent variables whose solution, whose values on the output of the prologue program will be types. So what variables are we going to invent for this function here? How many do we need at least? Let's try to write them down. So we'll have two, presumably these are, I call them i and o, and this will be the type of n, the input. This will be the type of the return value. Do we need some more? Or would it be more convenient for us to have more variables, just to make it easier to write that prologue program? So how about if we did it this way? Here is our AST. What operations these are doesn't matter, but this is an abstract view on an abstract syntax tree. If I want to invent these prologue variables to keep values of types, what would be a convenient place to invent a new variable? I could have a variable at each node. So we could have a variable sort of t1, t2, t3, and these would denote types of the value that that particular subtree computes. That would be a clean, systematic way. Perhaps we would have too many variables, but who cares? So we have those variables, but let's now come and see what we really need to do. We need to compute the type of the parameter n, the return value of that factorial function. And we also need to check whether those types that infer all check out. It turns out to be we'll design it in such a way that we will only be able to infer types if the function is in the typeset, meaning it uses those values in a way that it doesn't add a floating point to a string. OK, so let's write first the axioms of our arithmetic, essentially the axioms of the operations of the language. We'll do it in prologue. So what am I saying here? I'm saying here that the type of the value 0 is int. The type of the value 1 is int. Really, if I wanted to do it in prologue, I would have to do this for all literals that can appear in the program. So you imagine that I have done it. So this is a prologue fact that says constant 0 is of type int. You see a problem that it would be really hard to do it for floating point literals. But I could create these rules on demand as I encounter these literals in the program. What other axioms do you think we may need to add to do our type checking? We need to describe the semantics of the language with some prologue facts. So we have a multiplication in that program. How would we describe multiplication? Presumably, we want to describe it once and for all. So you will have inputs. So if you get int, then you are saying we would say multiplication here. And we probably want to show also the return value. Somewhere. So what would we do? We would do outputs. It is a possible way to do it. Essentially, you are saying that multiplication has two arguments, and they are ints of type int. And it has one output, and that's an int. OK. Do you see a problem with that? There could be a little challenge here. All right. Exactly. So we have inputs. Imagine I do a float, star, float, when I presumably do outputs, star, float. Now you could couple this relation on input with this relation for output and think that int times int is a float, really first. Presumably, it's not the case. So let's try a different way of modeling the types of multiplications. And this is actually what we'll do. We'll do multiplication either accepts all two ints and generates an int, or all three are all both arguments, and the return value are a float. And now we are coupling together the input arguments and the output arguments. So how about subtraction is the same, and equality same too. So these rules are specific to the language. They hold for all programs. They refer to the semantics of the program. So what do we do next? Now we need to take this program that we haven't translated into rules that are specific to that program, and this is the program that we'll run and it will perform inference. So could we start by some rules? So I spread out these programs here, and can you pinpoint some point in the program that will result in some prologue rule? So let's start with the first rule. Does somebody want to give me the first prologue rule? You could think of it as a type constraint induced by this program. So can you think of a type constraint generated by the program? So remember we used i and o for input and output. So the type of n is o. The type of the output, I'll put it here, is o. The type of o must be comparable to 0. So let's see if we can. Type of i must be comparable. Well, do we write it like this? So what is a bit? It's a good rule, but it's not quite correct. So can you spot a little inconsistency there? Can people see what's not quite correct with this rule? So presumably this rule, let's just say where it comes from, it comes from this comparison. And we are comparing indeed the type of n with the type of 0. But you are saying here 0, whereas we really want to say what? Type of 0. So we want to have a rule which says type 0 is, let's call it t0. So we'll bind this variable to the type of 0. And now we'll just say here we want to move this. See, if it was written in a really type safe language, it would presumably not happen. I'll deal with it. So in the meantime, think of what other rules we want. It's a shame that this is what you need to do. I'm sure that Windows 8 is going to solve the problem. OK, so here we are. So remember what we did. We said the type of 0, and this is that 0 here, is going to go to variable t0. And now for this operation, we are going to say comparable i, which is the type of n, to t0. What other constraints do we need to generate from this program? How about the fact that value 1 is going to be returned from the function? Can we turn that into another rule? So we need to get the type of 1, all right? So we have agreed that the type of the return value of the function will be stored in the variable, the prolog variable 0. So that variable could be int, flow, string, whatever that function happens to return. And so this means that t1 must be essentially the same as 0, right? Must be the same type. Now, 0 is already a variable that stores that output type. Yeah, maybe I should call it t0 for output or r for return, but it's 0 for now. OK, what about some other constraint? We could write it that way. If that is preferable, we could say equal. And this is just the prolog rule equal, which insists that these two are equal. It will unify them in the term unification sense that you know. Well, how about this? Can we turn that into a type checking rule, a constraint that must hold over the types that be assigned to this function? So we'll need multiplication here, for sure, which is three arguments. One argument here, the other one here, and then the return value of that multiplication. So what are we going to put here? That should be easy. This will be i, the input type, the n. How about the second argument? Now it gets a little bit tricky, because we are calling a function whose type checking we have not yet performed. So what assumption simplifications are we going to make to make it possible to type check recursive programs to begin with? And indeed, this is what we'll do. And we'll do it on this sort of agreement we made that if there is a function, it will return the same type each time it is called. So if you have a recursive function in JavaScript, Lua, it could return a different type at each level of the recursion. You could write it that way, and the program could still be quite correct. Not sure that it's good software engineering. Might be horrible software engineering, but the program could be correct. But here, we agree that if the factorial here returns all of its instances will return the same value. So the type of this is O, and the type of that is also O. All instances of fact are O. And what is going to go here? It would be another O, but I could be a little bit more systematic, perhaps, and say, in when the temporary variable, I don't know, call it TM, and now say equals TM and O. Simply, I would be saying that the type of the value of multiplication is TM, and it must be the same as O. Essentially, I'm saying that both branches of the if return the same type. Are we missing anything? This cannot possibly be all. It's a short program, but you know short programs generate a lot of code, stuff, bytecoded. So what we might be missing? Can you speak louder? Uh-huh, OK. So this one, perfect. So we need to say that the sub of I and T1 needs to return I. Perfect. Good. So we have that. What else? There must be at least one more. Yeah, we should probably do it. Ideally, every sub-expression would have its own variable as we agreed on the AST, and then we would have these equalities binding them together. But let's forget that. That's cosmetics. But there is one constraint that we should really type check. Yeah, I think I'm doing it here. I'm saying that the type of here is T1. I'm making it equal to the output value. And the type of this is TM, and I'm making that equal to the output value as well. So this is where it happens. Here is where I say the two branches of it produce the same thing, because they must be both equal to O. If you wrote a syntax-directed translation that generates the prologue program, which you can imagine now doing, it would look slightly different because I'm oversimplifying since I'm doing it by hand. But there is one more expression that we are not checking. Does anybody see the expression? We are not checking for a property that would crash your 164 interpreters. But in a language that is somewhat more decent about not allowing any values anywhere, yes, we should check that this one here is a Boolean, presumably. Let's not write it down here. So here is the whole program. And essentially, what I have done, I looked at the function factorial. I have written down the constraints, a little bit more compacted, fewer equalities than we've seen before. And look what I've done. I defined a rule, factorial, that in its body has all the constraints for the statements inside that factorial. And I'm using this term here. This is our notation for I arrow O, which is the type of a function. And I could do it for all the functions in the program. And I could refer to these functions from here. So a factorial called function foo, foo with some constraints, I don't know, a, o, t, 0, would appear among the constraints. So if fact calls foo, it would be just another constraint over there. So now let's see. Let's try to actually run it. So here is the program. Here are our axioms for the arithmetic of the language. Here is what I just typed. Now we want to ask the query. This query here has one variable for which we are asking for the type. And this is essentially the type of this factorial variable. It will be a function. Sorry about that. Now I can ask. So what answer do we expect? Do we expect int something else? Int int, and it will be in this notation, right? The term fun int int is our way of writing the syntax int comma int. Should there be more solutions? So try to look at that constraint system expressed in prologue. Should it find more solutions for that function? So how could we now make the language a little bit more flexible and allow the factorial to go from floats to floats? Because in principle, why not define a factorial over floats? So what extensions do we make? Yes? So if we do that. So now we are saying that 0 can be both int and float. And now I'll rerun it. These are the two solutions here. OK, so let's try to understand what we have built. Yes. OK, I love it. So the question, I'll paraphrase for others, is that I'm being inconsistent because I'm not treating the factorial, which is a function, the same way as equality as multiplication and everything the same way. And indeed, I should, right? Because multiplication is really not an operator, it is a function. And I should do it. The rules will be a little bit bigger, because I would need to check, yes, is it a function that extracts the input and output? And if I want it to be proper, I would do that, except the constraint system would grow a little bit out of hand if I had to do it by hand. But absolutely true. OK, fantastic comment. Now, what can I do with this prologue program? So imagine I am a type checker. And I see in my program that somebody calls a factorial with an int. This is how the type checker essentially determines what is the return value. It's an int. I can also, when I see what the return value is, I can determine what is the input value. It can only be int. So this is now something you can use for optimizations. Because you know what is the type of the variable you can create much better code than code which a runtime needs to distinguish between integers and floats. So this is essentially it. Now, what I want to do is switch from this little example where we saw how the inference happens. And indeed, it should be more proper and operator should be handle-like functions. But this is somewhat pedantic at this point. So let's look at the language ML, which is the language that pioneered this sort of type system. This is the language that you will see in your programmer life. There will be less of the Java style type systems. And more of this partly because it does the inference for you and you don't need to type the types. You don't need to enter them manually. But because it is also a little bit better for extensibility of programs. And Scala sort of mixes this type system with ML's type system. So first let's look at function definition. So this is essentially just purely syntactic thing. But it is interesting that when in ML you define a function, you have these two cases. Here is the first case and here is the second case. And you can reason about it mathematically. You see, oh, factorial is a function which on zero argument returns one. And on an argument that is different than zero returns this. So you can now see that these are the two bodies of the function. And this is a case expression that does pattern matching on the input. But this is a purely syntactic thing. The inference is just like before. When you run the compiler, the compiler does the type inference that we just performed. And when it is happy and it can infer types, meaning there is no type error inside the function, the body return from the compiler is that. So can we now decode what is the meaning of this? Can we go word by word in this and try to understand the output of the type inference? So essentially, the output of the type inference is a checker for you. Type the function. You don't need to annotate any types. The compiler does the check, comes back to you, and you look at it and see, oh, it makes sense. This is actually what I intended. It may be that it doesn't type check. It could be that it type checks to something else that you wanted. And then you have a hint that perhaps there is a bug in your program. And in fact, type checking in these languages is so strong that it may take you a long time to fix the types, fix the bugs that manifest themselves as type errors. But once the program type checks, it's almost always going to run. There are people who will swear by this, right? Yes, but debugging the type errors may take quite a bit of time. But then the program just runs, since all bugs have usually been found in fixing the type errors. So what does this keyword mean, you think? So fact would be sort of a variable, but it's not quite a variable, right? The reason that this is a value rather than a variable means what? That it's immutable. You cannot reassign it the way we happily reassign it here. So it is a value rather than a variable. But it is a symbol that has a name. And here is the type of the value stored in it. And what is the value stored in fact? It's a function. This is what you see. It's a function from ints to ints. Pretty compact and convenient. So let's look at lists. This is the cons operator, the double colon. Nothing that you have not seen really. And so it is the same as that. So there is little syntactic sugar to simplify this notation into that notation. And really, as you said, it is just a function, binary function, but it has infix syntax. So you write it the double colon between its arguments. No magic here by now. So look at this function here. Try to understand what it does. And tell me the type that I need to put here. So we'll do a manual type inference. So who can give the type of that function? So sum of is a function. So it will have the type of its parameter and its return type. So let's start with the return type. What is the return type? You could cover the second line and look at the first case of the function that should already give you a clue if not the whole answer. It would be an int. How do you know? Well, it's enough to look at this body and you see that this function returns int. So the second body better agrees with it, or it would be rejected by the time checker. Indeed, we see a plus here. So it looks like it could be an int. Now we look at h since this needs to be an int. The whole thing needs to be an int. This is a plus which works on int. So this then is an int. This gives us a constraint on h. So let's do this reasoning again. The return type is an int. We know it from here. So this one is an int. This is a plus that works on ints, as opposed to plus that works on floats. What do we know from that? We know that the return value of this must be an int, but we already knew that. So what do we know about that? h must be an int. So what kind of list is that? What kind of elements are in the list? It's a list of integers. So we'll say it this way in ML. It's an int list. If we had a list of ints, it would be int list list. That's just a syntax. And notice how we did the reasoning. We knew the types of o. That would give us the type of that. Then would give us a type of h through the addition. This would give us the type of the head. And now we know it's a list of ints. But there is something we need to clarify. We only concluded that this particular head of this list is an int. What about the other elements inside of the list? Yeah, we'll get to it soon. I'll give you a simpler rule that in ML, in order to make the type checking work, there is the agreement that you can only have homogeneous lists, lists where all the elements have the same type. So each instance of the list is not polymorphic. It needs to contain elements of the same type. And that's another price you pay for having static type checking. That you now cannot create lists where this is a string, this is an int, which you could, of course, happily do in Python. Not that you should, but you could. Yeah, so there is another way to derive the constraint that we do have a constraint on t. It needs to be a list of ints. And because the function is recursive, it would fall out that all elements need to be ints. Looks like you have a question. OK, so let's get to the empty list in a second. That this empty list really must be an instance of the type list of ints. Indeed, it's an instance of all kinds of lists that you can create. All right, so how about this? What is the type of this function, which is your map function very familiar, right? It's a function that takes a list, takes a function, and applies this function on every element of the list, and returns a list with every element applied. So just to be sure what we know we are talking about, when you have a, b, c, it returns f of a, f of b, f of c packaged into a list. So what is the type signature of that map function? So we are making an assumption here, right, that f is what? A. So under this assumption, under the assumption that f is a function from some type A to some other type, the same type A, of course, then this would be what? A function that map would be receives, oops, a, right? This is the first argument. That's the function. The second argument would be a list of As, and the result is what? Also a list of As. You agree with that or no? So it is correct. The map is of that type, but is this the most general type? So it is correct that if I give you a function from A to A here for f, then of course the list must be a list of As, where A is some type. The result then is a list of As. In what way is this not the most general type that the compiler can infer, please? What could f be? It could go from, yes, from A to B. So now, indeed, we have the function, the type of f is as general as it can be. Cannot be more general than that. If it's a function, it needs to go from some A to B. Now it must take a list of As and produce is now a list of Bs, right? Excellent, OK. And it has two arguments which is denoted by this star. And you can indeed use it in two different ways. You can give it a square root and apply it on a list of loads or a reverse function and apply it on a list of lists. It will all work, OK? So these are really polymorphic types in the sense that now we have a list with not a specific type inside, but a special parameter. It's written as quote A, which really is a way of saying this is some alpha, OK? So this is a polymorphic function, right? The cons is a polymorphic function. Now how would we do the type inference here? Now we have a type inference with types that have this special funny type operator. Some kind of list. So how do we encode some kind thing? So can we encode it in prologue and somehow do a type inference where the output of the type inference in our prologue program will be a type of alpha, OK? It looks like we have some proposals. So that variable, the unknown thing, would be just the A type. So let's see if it will work for our, let's see if we could do it this way. Actually, I'm not sure it will work out, but let's imagine that multiplication can work on this. Can we predict what will happen now? Maybe this is a quick hack that is not going to work, but let's see. So this one, because of other constraints, didn't give us the unknown solution. We would need to encode the floating list, and I'll try to do it on the slides before I post it. But that's essentially the solution. Just use prologue unknowns for these alphas and betas, which are the parameters of the types. Here is a different version of the map that I want to use to close the lecture. I was hoping to do more brainstorming, but it actually did go quite fast. So let's see how this map differs from the previous map. Look at this definition here. Just pay attention to the arguments, and let's go two slides back, or one slide back, and see what we do here. So what you see is that these parentheses are missing. They are here on this slide, but they are not in this definition. So the first conclusion could be that, well, these parentheses for the function syntax are optional, but that's not quite the conclusion that we want to draw. What is going on here? It's a relatively deep, quite a deep concept that you can use to build domain-specific languages by embedding them a little bit better. So what's going on? So in fact, this is the proper ML definition. This is a function f with two arguments. Sorry, function map with two arguments, f and the list, and the second case is f with a list decomposed into two elements. So map is a function of two arguments here. The function was a function of one argument, and then the argument was what? It was a pair, right? So really the arguments are you there have nothing to do with grouping parameters for the function, but just creating the pairs. So let's see what is the type signature here. If you look at the type signature, now the type signature of map is very different than it was before. So compare this with what we have here. Okay, I'm sorry. Oops, right? So the type signature here, I should note it here is what? Map takes a pair where the first part is what? It's a function. The second half is a list of alpha, and the argument is a list of beta. I actually don't need the parameter here. The parenthesis here, okay? So this is the pair, which is the argument of the function, and here is the return value. If you look here, we see the function, but now it looks like it's a function of one argument, the supply f, and the result is some sort of a function. So what does that all mean? So maybe a simpler function that we could consider is, imagine we have a classical function of three arguments, A, B, and C, and imagine that the types of these are capital A, capital B, and capital C, and you return a value of type B. What would be signature of f in this ML notation? It would be A goes to... So what it means is that when you call a function with multiple arguments, say three of them, the evaluation proceeds as follows. You actually apply first the function to the first argument, and the result is another function, and now this function is applied to the second argument, and the result of that is another function, which you apply on the third argument, and then you get the result. So you could think of this application of arguments as if you were plugging in the arguments one by one, and after each application of one argument, you obtain a function in which that value is sort of hard-coded. This process is called currying, and let's see what we do here. We take map, and we give it just one argument, this function, what is the result? What is the type of this thing? Can we read it out from this? Okay, so this is the type of the square root, and it is real to real, and this would be the type of squared all, okay? So what is square root all? It is a function that goes from reals to reals. So by applying the first argument, just the function passed into the map, we did obtain a map function, but it's a map function in which the function that will be applied on every operator, the mapping function will be already hard-coded, and so now you give it the second argument, the actual list of reals, and it produces the right value. So what's interesting about that, that using this method, you can now create essentially custom operators for a DSL, if we wanted to define DSL this way. So now we have an operator square root all that performs a square root on lists of reals. We do not need to mention map at all, and this is all we need to create, by essentially hard-coding the square root in it. But square root all is still a function, except some arguments have already been provided. So this seems like a convenient way to create new operators, so why don't we do it in our Lua kind of language? Seems like it would be handy to have. Turns out that you can create embedded languages for parsers in a really beautiful way by relying on this process of curing, creating functions of three parameters, supplying one and getting two. And you can write expressions that look like grammars, but they really are just function applications. But visually they look like context-free grammar production rules. So why didn't we add such a curing capability into Lua? Why isn't it in Python, for example? So we are relying on some particular property of the language to make this possible, or could we just add it into Lua? So can you do such curing in Python? Can you give a function name? And the function is of two arguments, and you just supply one of the two arguments, and the result is a function. You can clearly create an operator curing, which receives a function, and the first argument gives you back a function that is essentially a curried version of the original. But you cannot do it in Python with the syntax that we do here. Just call a function with this one argument, right? You need to call a special operator to effectively wrap your original function with a wrapper that provides that curing. Do we need that? Okay, so why would it conflict? It's an interesting language design question. So if I understand correctly, you're saying that Python does not or does have function overloading? So Python does not have function overloading, typically, right, because in a language like Java that is statically typed, you could have multiple functions with the same name, and then you choose among them based on the type of the argument, right? And typically you make that choice at compile time, but since the language doesn't have static types, you cannot make that choice. So you don't have that overloading. Right, so the answer is that perhaps Python has something similar in the form of the default parameters, right? Maybe you have a function foo and y, where y gets the default value one, right? That's what we have in mind. And now I can call foo with value two, and I do get the result back, right? But if I do this in ML, I get something different, right? I get a function that still needs to receive the second argument before it is evaluated. In Python, when I call foo with one argument, it automatically supplies the value for the second, and it executes the body of the function and gives you the return value. So it's not the same thing, right? I see, I see, I see. Okay, I'll tell you why I'm misunderstood, because typically by overloading, we mean having multiple functions with the same name, whereas I think what you meant was default values of parameters, okay? Yeah, so that would conflict, absolutely, all right. But even if you remove it, so if you remove it from Python, could we then obtain curry? Because it would seem convenient to just obtain these partially evaluated functions that you can then pass around. The arguments to functions are evaluated just like in LUAS, and it's passing arguments by value. You evaluate the expression, obtain a value, and then you pass it into the function. So immutability, sort of orthogonal concepts here, it has passing by value, right? So you can do it explicitly by wrapping a function in lambda with one fewer argument. The question is, could we get this sort of syntax that we really just call it with one fewer arguments and the return value is this partially evaluated curried version of the function? The curry doesn't have anything to do with food, by the way, it's based on a mathematician who worked on functional programming languages. Uh-huh, okay. So we would need to know, so you're saying let's add that feature into the interpreter, what would we need to do? So let's do this exercise. We would presumably need to restrict the ability to give a variable number of arguments, right? That would need to be fixed. So when you see a call, you read the arguments from that call, okay? And then you pass them into the evaluation of the function and if you have all of them, perhaps you evaluate the function. If you have fewer of them, your return is partially evaluated function that needs later to receive more arguments, right? Is that all we need to do or would it break down somewhere? So it seems like it could work, right? You could perhaps even play with the syntax and avoid these parentheses, right? So as long as you make the agreement that we are strict about the number of arguments of the function, so you don't allow variable number of arguments, then you could call a function with a partial list of arguments, obtain that function as a first class value, pass it around, pass it into another map and so on. And this way the functional programming would become much more interesting because you could create the harder functions that you need to pass to maps and folds that could be created from other things, from other maps, for example, by plugging functions into them. Uh-huh. Yeah, you would have one function with the, that's right, one map function. It could be polymorphic, right? This function map is polymorphic in that it works on various kinds of types. But you couldn't have another with a smaller number of arguments. You cannot have that in Python either, I believe, right? So in that sense, we would not be losing anything. So that's all, I will try to add one more example into the slides before I pose them off where curing is useful to create operators that make functional programming somewhat easier compared to wrapping these functions into lambdas which adds a lot of fluffy syntax, okay? So that's it for today. I look forward to the design meetings, later tonight, and what we'll do on Tuesday is look at how tools can automatically analyze programs for bugs, for information that can then be used for better optimization in the compiler.


The world's most honored watch is Laun Jean. Laun Jean watches have won ten World Fair Grand Prizes, twenty-eight gold medals and more, honors for accuracy than any other timepiece. Laun Jean, the world's most honored watch, is made and guaranteed by the Laun Jean Wittenall Watch Company. And for the Laun Jean Chronoscope, a television journal of the important issues of the hour, brought to you every Monday, Wednesday and Friday. A presentation of the Laun Jean Wittenall Watch Company, maker of Laun Jean, the world's most honored watch, and Wittenall, distinguished companion to the world-honored Laun Jean. Good evening. This is Frank Knight. May I introduce our co-editors for this edition of the Laun Jean Chronoscope? Mr. William Bradford Cuey, editor of the American Mercury, and Mr. Henry Haslett, editor of the Freeman and contributing editor of Newsweek Magazine. Our distinguished guest for this evening is the honorable author, Bliss Lane, former ambassador to Poland. The opinions expressed are necessarily those of the speakers. Mr. Lane, our Chronoscope audience remembers you for your appearance here last December, and we're very happy to welcome you back here tonight. Since that time, an investigation has been underway in Washington into the disappearance of 15,000 Polish officers, some 4,000 of whom were found murdered in the Captain's Forest in Russia. Now, we'd like to get your views on that mass murder because you've been very active in trying to get the truth before the American public about it and what has happened and what has developed about it. Now, I'd like to begin first by asking you when this murder occurred and what were the conditions under which it occurred? Well, in my opinion, Mr. Haslett, it occurred in April or May of 1940 when the Soviets were in charge in command of that district in Katyn, near Smolensk. When and how was it first brought out? It wasn't brought out until 1943 when the Nazis discovered the graves and that discovery brought about a great rupture of relations between the Polish government in London and between the Soviet government. Well, Mr. Lane, first, sir, why is it so enormously important in 1952 for us and for our government to go back and establish once and for all before the world the importance of this massacre? What's so important about the Katyn Forest Massacre? Well, Mr. Huey, if I may say so, first of all, I think it's most important that the people behind the iron curtain, and I refer not only to the Polish people and the Hungarians, but also the Russian people, should realize at last that the American people and their representatives are taking a very great interest in this case. But secondly, and perhaps most important, is to bring back home to the American people the importance of this because it shows what Soviet criminal methods are. And that's why tonight that we are discussing it and that's why it's so important is that it shows to the American people the nature of their enemy, how the Russians were capable of murdering large numbers of Poles and then use telling our people that somebody else did it. Exactly, because this isn't the only case we have. You see the case of the Ukrainians who have murdered Vinitsa? In many other cases of which perhaps we don't know nothing because there were 11,000 Polish officers who disappeared. We don't know their fate today. Well, what is the major evidence that the Russians did it? Well, first of all, the medical evidence, the condition of the bodies. Second, there's the, shall we call it, the agricultural evidence, the height of the saplings that were planted above the graves. Third, the circumstantial evidence, the fact that in the clothing were found documents that were not dated after April or May of 1940. Because let me say that's before the Germans got in there. Yes, because I was going to say that. Mr. Hassler, if the Germans had committed this crime, they would have had to be in August 1941 or after. Yes. But fourth, there's the diplomatic evidence, which I think is extremely important. From 1941 until 1943, the Polish government in London had been trying to find out where these 15,000 Polish officers were. And even our ambassador was trying to find out because of course the United States was equally interested in setting up a Polish army in the Soviet Union. And what did they say? They'd gone to France, Joseph Land, they'd gone to Manchuria, perhaps they'd gone back to Poland, perhaps they'd disappeared. And then when the Germans announced the finding of these graves, Pravda, the official organ of the Soviet government, says, oh, they were killed by the Germans while they were working on the roads near Smolensk in great coats in the August of 1941. The Russians have said that the crime was committed in August of 1921. Yes, but they were found in these coats, frozen in these coats with these great coats and so on. So that must have occurred then, at least the prior winter. Well, if I may say, it's to my mind most ridiculous that the Soviet secret police, which I consider fairly efficient, should not detect the presence of 15,000 Polish officers in Polish uniforms near Smolensk for two years. Now, Mr. Lane, let's get this fact straight again, if we will. The Russians caught 15,000 Polish officers in 1940 and murdered them. Well, in 1939, as they entered... That's right, in 1939. Oh, probably many more, but there were 15,000 that were known to exist in three camps. I see. Now, why did the Russians murder these 15,000 Polish officers? Well, in my opinion, it was for the purpose of stamping out the nucleus of the nationalism of Poland. All right. Now, were these officers intellectuals or were they scientists or what? Well, there were some who were members of the Polish Army Corps, but there were many others who were intellectuals and scientists. In other words, I think that Soviet policy is always to stamp out the roots of intellectualism in every country. In other words, the roots of nationalism. And they were, in other words, they were taking over Poland and they were not going to have any trouble. They were going to avoid trouble in the future by killing these men then. Exactly. Just as they did in 1944, they exterminated the... And then... When the bodies were found, the Soviets said that the Germans had killed the people, didn't they? Exactly. And then our OWI and our government also told our people that the Germans killed them. That's correct. That's correct. Well, that's what I'd like to get at. Yes. Why did our government put the blame on Germany instead of on Russia? And did our government know that Russia had done it? Well, now, that's a very difficult question to answer. Why we did it? But I think it's pretty obvious from what's happened why we did it. We didn't do... Our government didn't fact do this. The OWI didn't fact announce that the Germans had done it. They did. They swallowed the story of the Russians. And I personally feel that our government felt that appeasement of the Soviet Union was the most important thing in our policy. That's confirmed by many events that have happened since then. Now, the OWI not only swallowed it, but the OWI told our people that the Germans did it, didn't they? And how late after the war was the OWI and many major American journals still telling our people that it was the work of the Germans? Well, I don't think it has really been denied up to this day by our government. Because remember at Nuremberg also, we gave the impression that the Russians were not responsible. Because the indictment at Nuremberg against the Germans was just allowed to drop. And now, Mr. Lane, why is it so important now in 1952 why is it so important that our people understand this whole technique, this of lying technique on the part of the Russians? Are things happening in Korea today that our people should know about? Well, in Korea today, a ghastly repetition of cateen has taken place. I don't know the numbers because the numbers have not been admitted by our government. But there's certainly hundreds of thousands. In the middle of last November, Colonel James Hanley revealed that 6,270 American prisoners of war have been murdered by the Chinese and North Korean communists. Now, what happened after his announcement? Well, I don't want to comment on that, but let me say one thing, that those boys were found in mass graves, just the way those Polish officers were found.  And that's the thing that I think the American people ought to realize today that this isn't a matter that only concerns Poland or the Polish officers, it concerns the security of the United States. Well, hasn't this been minimized, these facts been minimized by the administration and dealing with the Russian negotiations Well, of course it has. Matter of fact, friends of mine in the State Department begged me not to take an interest in this cartoon matter. But fortunately, members of Congress have taken the matter up. And they've made not only the Soviet government so angry, but also the Polish Embassy so angry that vitriolic statements have emerged. And I'm glad to say that the State Department last Saturday came up and said that Poland today, the Polish Embassy magazine was suspended. Because of the attacks that they made on the United States as a result of Cateen. And the Polish Embassy had the temerity to say that the United States had murdered prisoners of war in Korea. Well now, sir, is there some indication that our government, our State Department, is at last about ready to tell the people the truth about this Soviet technique? Mr. Huey, after years of experience under the Department of State as a minister by Mr. Dean Atchison, I do not know what is going to happen. I see, sir. And I refuse to make a prophecy. I'm sorry. Well, Mr. Lane, I'm sure that our audience very much appreciates this very forthright message that you brought tonight. And thank you for being with us, sir. The editorial board for this edition of the Lawn Jean Chronoscope was Mr. William Bradford Huey and Mr. Henry Haslett. Our distinguished guest was the Honorable Arthur Bliss Lane, former ambassador to Poland. Now, suppose you said to your jeweler, show me please the best Lawn Jean watch you have. He would say, I have a wide selection of models to choose from. Choose the style you like best. The one you select is the best Lawn Jean watch of its type. Every Lawn Jean watch is a watch of the highest quality, correct in design, manufactured to the highest precision standards. Yes, every Lawn Jean watch is made to the unique Lawn Jean ideals of excellence. The ideals that have won for Lawn Jean, ten World Fair grand prizes, and twenty-eight gold medal awards, highest honors for accuracy from the leading government observatories of the world, and a position of preference in fields of precise timing, aviation, sports, exploration, and science. So if you wish to buy just about the finest watch made anywhere in the world, either for yourself or as a gift for someone important to you, you may buy and own or buy and proudly give a Lawn Jean watch for as little as seventy-one fifty. Throughout the world, no other name on a watch means so much as Lawn Jean, the world's most honored watch, premier product of the Lawn Jean Wettner Watch Company, since 1866, maker of watches of the highest character. We invite you to join us every Monday, Wednesday, and Friday evening at this same time for the Lawn Jean Promiscope, a television journal of the important issues of the hour, broadcast on behalf of Lawn Jean, the world's most honored watch, and Wettner Distinguished Companion to the world honored Lawn Jean. This is Frank Knight reminding you that Lawn Jean and Wettner watches are sold and serviced from coast to coast by more than four thousand leading jewelers who proudly display this emblem, Agency for Lawn Jean Wettner Watches. This is the CBS Television Network.