{"id":"GsWGxQbcYsw","title":"Learning Daml: Data types and imports","description":"📖Get started with Daml: https://bit.ly/tryDaml\n📚Learn more about Daml Smart Contracts: https://bit.ly/learn_daml\n📮Check out our blogs: https://bit.ly/daml-blog-engineering\n📋Become a Daml certified expert: https://bit.ly/daml-certification\n\nLearn about functions, records, sums and how to import other packages in this Interactive Learning Tutorials (You can try it yourself here 👉  https://bit.ly/learn-daml-fundamental). Those interactive tutorials provide you with a pre-configured instance, accessible from your browser without any downloads or configuration.\n\nChoosing the right types for your data will make a big difference for the efficiency, complexity and clarity of your code. Furthermore, data structures can encode important invariants of your code. Examples are non-empty lists or optional fields. DAML truly excels when it comes to modeling data.\n\nIn this scenario you will learn about\nbasic data types of DAML: functions, records, enumerations, sum types and type synomyms\nhow to import your own modules or the standard library\n\n#damllearn #distributedapplications #smartcontracts","channel_name":"Daml","published_at":"2020-09-17T00:00:00.000Z","thumbnail_url":"https://i.ytimg.com/vi/GsWGxQbcYsw/hqdefault.jpg","transcript_text":"hi everybody uh we're actually starting a new series now my name is anthony i am a developer relation i do developer relations at demo and today i'm going to be taking you through one of our online interactive tutorials that's at demo.com learn you can see we actually have quite a lot of tutorials so in this series i'm going to be working through them one by one it'll be similar to the other series where i went through the damn cheat sheet except this is a little more in-depth and of course you know if you don't want to watch the videos and want to try these out yourself just go to donald.com learn and you can start them up each and every one of these scenarios gives you a complete demo platform essentially the entire demo ecosystem inside of your browser so that you don't need to download anything you don't need to install anything everything just runs it works so what we're going to do today is we're going to do data types and imports so we're going to learn about how functions work in demo records sums and how to import other packages and all these very basic things with demo so this scenario says that it'll take about 30 minutes i feel like this video is going to be a little less it'll probably be about 15 to 20 minutes so let's get started all right first we got to fire up our ide because we're going to be doing a lot of things in that um but yeah one of the first things we're going to be doing is we're going to be looking at essentially how we declare a type in demo and kind of uh then how do we assign a value to it so right here we have our first type uh our first variable and that is answer and it is of type integer and then we can assign a value to it and we can say answer is equal to 42. uh this is basically since this is demo and it's a a functional language and i i'm not using the term or not i didn't use the terminology fully correctly but this is actually a constant function which basically means that answer is always going to return 42 from now on and that's a very basic basic type but we can have much more interesting types and functions so we're going to define here a square and square is a function that takes an integer and gives you back another integer and you can actually see that in the type definition here you have your first integer and then an arrow and it'll point to the second integer so that's basically saying that the chain starts over here and the chain ends over here and what you can basically infer from that is that you will take in a number and give out a number because whatever is at the end of this so for example if there were three of them there's this one type check now but if there were three of them whatever's at the end is what's going to be returned and the others are going to be arguments going into this function so for example to make that actually work we could do you know squares x times y which of course it isn't so that would be something like like multiply and then we have a function now that takes two integers and does something and returns an integer and as we're going to see it's actually very powerful see these function definitions are very powerful because you can actually know quite a lot about the function itself without reading what it does like you obviously still have to read what it does but you don't have to read what it does all the time in order to kind of get an idea of what it is and also i'll show you later you can even take that idea and say i need a function that does this like i know what this i'm not going i don't want to write this function but i know that this function will take an integer and it'll take some text and it'll output some other text or something to that effect and you can actually knowing what you want your function to look like you can actually then go and look up your function in something called hugo that we use at demo which is a pre based on uh haskell's hugel search engine where you can basically say i have a function that or i want a function and i want it to be do this thing i wanted to take these arguments and give back this argument and then you can go and look that up which is really really cool when you're when you're trying to find out what the thing you want to do is called without having to go and regularly google it but anyway we can have you know more advanced functions yet again like i demonstrated before with the multiply example where i turn square into multiply here we have a function that can do diagonals and this one you know it'll take two decimals and it'll output another decimal and yeah so that's really cool so knowing all that we know now especially knowing what we know about function definitions how can we answer this question and the question says you know which of the following uh is the type of a function that returns the number of occurrences of a given character in a given string okay so looking at this question we want the number of occurrences of a given character in a given string so we know we want our function to contain three things we want our function to return a number which would probably be an integer since characters can occur half of a time or any any fraction of a time like that uh we also know that we want it to be a string to figure out what character how many of those characters are in a string and it's returning the integer okay so we have then essentially just one option here where we have the character and a string that we're going to give into it and it's going to give us back an integer that sounds a lot like what we would want and i'm not actually sure if this one's in hugo but let's go find out so just to demonstrate here go to google.donald.com and we say oh we okay so that one doesn't exist so there is no function presently in demo that will do that for us but if we wanted to work on an into an end we could look that up and fund them and i'll probably find a better example as we go through this but that's just kind of what you can do is you can go and take these types that you know about and say oh hey i want to take an integer and i want to output it as text how can i do that and then oh i have this where i can take lots of things and i'll put them as text maybe that'll work and let me go back here okay so now we've we've done that and now we also want to actually use diagonal and try it out there are several ways we could do this because we need to answer this question of diagonal what's a diagonal of three four uh we have several ways we could you know go ahead and use the download repo we could use demo script which is uh the way you're recommended to start doing things with demo when you want to do operations on a ledger and and do tests and setup and tear down but right now i'm just going to use scenarios which is the previous version um i don't believe our catacota version yet has script in it but by the time you're watching this video it probably will have scripts which is actually very similar just a bit different and a bit more powerful and a bit more consistent but anyway let me go ahead and uh write out our scenario so we write out scenarios by saying scenario do and then what we're going to do is we're going to take our diagonal and we're going to say diagonal 3.0 4.0 and just return it okay and then we can actually run our scenario in our in our browser here and this is actually you know it's starting up a demo sandbox it's actually processing everything and then it's returning the values and so we could see right here we've got our return value of 4.999 uh pretty sure that rounds up to five so let's select five and continue hooray we got you got the answers correct so then moving on you know we have lots of other interesting types too that we can use in donald that are also fairly similar to what you would find in haskell and one of the most basics is a record type so what a record type does is it allows you to take a variety of different data and put it together so that it forms a cohesive hole so rather than saying you know having street of type text and then city of type text like these two things we know that they go together so if they go together we can just make a record type and here we have this record type that stores an address and it stores a street city and country and then we also have a very interesting and useful addition here that if you use haskell you'd also be aware of is we can derive a lot of things here so that these record types can be used in other ways with other functions just as a given so uh we can basically say you know deriving equality and show and so what this basically does is it makes it so that we can now test for equality across our record types so we can see if two addresses match each other um and we can also show them which means we can make a text representation of all of them uh since demo is based on haskell it has this very powerful type system where it essentially can go and say okay i know how to print text uh on a screen and i know how to convert an integer to text i know how to convert a decimal to text okay i can just show those without you having to write code to say this is how you do it and it's also important in within demo for record types to have uh a quality and show on them because then that means you can use them in most other parts of demo particularly when we're writing templates as i'll show you later we need to have those those uh those type classes on on these record types in order to make sure that that that the template can actually handle them because if we remove them then it wouldn't but just really really uh specific stuff just know that whenever you want to actually use a record type in demo you should be deriving eq and show and so here we have another record showing that records can actually be nested here we have a person that can have a name and an address and that address obviously corresponds to this record type so they can contain that and then we within that person you know we can store all these records and then their address is also a record within their record uh again you know if we want to we can go ahead and we can say deriving eq and show and since we demo knows how to print and test for equality on say an integer and also an address as a result of deriving them over here it can go ahead and just derive that again for itself and so if we were to create a record we would go ahead and do something like this where we would essentially say okay here's our person that's their address the city country age and so on uh you know very basic but this is just the syntax you would use it looks quite similar to jason and then once we've actually gone ahead and done this we have several different ways that we can pattern match and access different parts of the of the record so for example here we have a function that pre-prints somebody's address and the way they can do it is by using positional arguments because we know street occurs first city occurs second and country occurs third we can say we're working on address types and we're taking things out of these positions and then printing them the problem with that particular approach is that if you have something where say city is first now it's going and the types still match now we're going to end up in a situation where city and street are in the wrong order down over here so that's not good so there are other ways to do this that i would actually recommend doing over this this particular approach but this is definitely one useful way you can do it uh especially in cases where you're working with something that things that might not be named like tuples but the other way that i would recommend doing most of the time especially for record types is to go ahead and use the field accessor so you can say oh address.street address.city and now when these things are moved like cities up here it doesn't affect it so yeah now we have a few questions so first and foremost you know what would the following return testperson.age we can kind of look and say it would be seven and then what will the following return if we were to pretty print the address we can go ahead and run that really quickly steeple scenario do and we'll just run that and we should turn this oh also not really part of this lesson but you'll sometimes see me using these dollar signs dollar signs are essentially shorthand for do everything to the right of this first and then do the stuff to the left uh you can think of them as equivalent to using parentheses around around uh around different parts of of your functions and does the same exact thing so we'll run it and get our results okay we can see our return value screen is a little small here so forgive me but that should be our return value for when we run that function and it does exactly what we would expect it to do you know it goes ahead and it get prints the street separates it city separates it by some text country perfect and so basically what we can then do is we can go ahead and use these record types in templates and what what it says right here what my co-worker robin wrote when he was creating this example is that we can essentially think of a template as a record type but with some other things on it you know it has parties and signatories it tells you who's observing the contract who can use it and do what with the contract and that's you know super super interesting in that uh can really just treat these things fairly similarly and we can we can just kind we can really if you know if you know record types from haskell you can kind of just imagine a template as a record type that is simply going to be a record type that will commit itself and store itself somewhere so record types themselves like if you make just date a person and you run your program if you're not saving it anywhere you're not really committing it anywhere and you're not really setting any rules on it what templates are are basically record types that you can easily commit to a ledger or some sort of database and that you can actually set more permissions and rules around which is very interesting and yes so just to demonstrate too if we remove the deriving uh and the eq and show we oh sorry i should remove the whole thing what we might end up with is oh never mind i removed it from the wrong one that's why that wasn't working if we removed arriving just to demonstrate what i was talking about before we now see that our our template can no longer use our record type and so here the type checker is actually very helpful it'll tell us oh you should use a deriving instance because we can't derive an instance for equality on the person contract because address doesn't have a quality and then it'll show you the same thing for show it'll say we can't you know we don't know how to print this um we don't know how to turn this into text so can can can you derive this and it basically is saying go ahead and add deriving to it and then we can go and and test out some things so oops let's call this test two so the name doesn't conflict and here where you know we're just going ahead and creating a person contract on our on our ledger and we can see that they now exist and now this is very similar to the record type except rather than just being stored in memory and then later forgotten and this is actually something that's been committed to a ledger this ledger in particular of course is in memory but many many ledgers and databases also will just write to disk so yeah anyway we answered the quiz correction we answered the quiz questions correctly up above i believe so let's move on to the next thing the okay so our next very fun data type is enumerations these are very similar to enumerations that you would find in many other languages basically you have this data that can be one of several different things and you can go ahead and specify them so here we've defined gender and then you know we want to extend our gender function to allow other genders to be specified in a in a general sense and then we can go ahead and say okay now our options are m f and other and you can provide text for for that other option you know you can also extend these so that you have all them all sorts of genders included uh this is just kind of showing too that you know you can have this enumerative type but your enumerative type also is able to enumerate not just that to that specific type that mf but it can actually contain other types within it so you can even for example you could add text to any of these so you can add qualifiers for all these and then work on them i don't think the way these functions are defined here is going to actually you know what we'll leave one it'll throw some errors but then we'll show how how that works so here we have our type and then what we can do too is we can go ahead and handle all those cases so for handling cases of these options we can go ahead and say okay well what we want to do is we want to is we want to print these things so we can say here's how we're going to handle our cases and it's going to also make sure we handle all of our cases or that if we don't we can have a case where we handle all other cases that we we weren't interested in so for example here we're getting a bit of an error and i'll go into that in a second but we can say okay in case of m we're going to print mail in case of f we're going to print female in case of other we're going to print o which is which is that text attached to other but male also has a text attached to it here so in order to in order to deal with that what we can do is if we weren't interested in the text we can say bottom and what that basically does is that lets us discard uh that text there because we weren't interested in in printing it the other way we could do that too is we can you know we could assign it as as a give it a variable but we just wouldn't use it but in general the the best way to do it is that and then for example if we wanted to you know uh just print if we wanted to just handle any particular case we can do this and we can say you know bottom any of these types we should just print some text and that's it um yeah so that's the that's the way you would handle those different cases of having these of enumerating these things anyway i need to just reset that so that when we run our functions we'll get the right thing okay so if we do pretty genzer m we can it'll go ahead and return mail and then if we were put hello world as a text it would return that so we can go ahead there so now with our the next thing we can work on is type synonyms uh what this essentially means is that when we're working with these types we don't always want it to be an integer for example so here's a great example is uh a phone number when when we have a phone number you know we might represent it as text or an integer or something to that effect but we don't want to call it just text because it's not just text it has other meaning to it and so what we do here is we say you know okay we're taking a phone number and then we're printing some text and we're basically saying you know our we've gone ahead though and said oh our phone number is actually a type and the type is actually integer so integer and phone number are now equivalent to each other if you have a function that works on an integer i believe it'll work on a phone number let me just check that really quick um a pretty phone number yep it'll work so yeah essentially they if you have any function that works on an integer it also work on a phone number now because they are the same we're just using that that type name as a convenience so that we're much more informative as to what type of data we're really really working on so let me just delete this here okay and so the other thing we can do too is we can go ahead and uh change the phone number to actually be a variety of data and so what we can say is oh we want our phone number to be not just an integer because just an integer is not enough data to represent everything so we can do here is we can have uh it be another it be a data type it'd essentially be a record type and we can do we can we can have you know the variety of different digit groups and then we can go ahead and you know represent those in much the same way we represented addresses when we were pretty printing them and so yeah you can also go ahead and import your own modules so what this basically means is that you know if you have fairly common functions much like you would in any other language you can put them in a module and then go ahead and import them in this case you would be able to say go ahead and import address book um i won't work through this particular part in too much detail but if you want to try it out yourself you can go ahead and check out the editor and you can then go and take your address book take your data and put everything that's common into you know your your library and then go ahead and import that and you also have a variety of ways to import data so you can import data very specifically you can say i want to import things but i only want to import these things from from address book like i only want to import address i don't want to import personally because i'm not using the person representation on things or you can say okay well i want to import dress book but i want to do a qualified import i want to go ahead and import it you know as a so then i can refer to the person in and addressing them as a.person and a dot address instead of just importing them at the higher level it's very useful too when you want to you know when you're working with a lot of different libraries um qualified imports do come in handy very often in demo and so we have a couple more questions here so which of the following function types will be in scope after the import statement import address book this is a tricky question too i actually i answered this one before it was a little tricky uh the answer is actually most of these things so the constructor that actually puts together the address will be it uh the address type and so what i mean by that is your constructor is over here basically says how the address is formed how it's constructed uh and then your type is over here basically says okay this is this this is the address type and so this is just something to keep in mind is that you know when you say a data address equals address that sounds kind of redundant but it's there for a reason because one is the type and one is the constructor for that type and so the other things that are available are street obviously city country look up is not available but length is and that's why this was a tricky question because length is always available it's part of the prelude endemol um if you're coming from a high school background that's the same as the prelude in haskell it is the portion of the library that's always imported so the for very common functions like length there and there and then okay which of the following function types will be in scope after the import statement import qualified address book as a well a dot address the type should be a dot street should be and length should be let's see if i've answered those correctly yep i did yay okay and then yeah so the same way you could import your own your own libraries your own modules uh demo also lets you import demo also comes with a lot of a very useful modules so for example you know you have da.date so if you wanted to import da.date you can go ahead and do it here and then you could say okay we want oh not an address we want to add a birthday to this type of person and then we can say their birthday we're going to have it be a date and so once we do that though we can actually see that our some of our other functions broke um in particular the test person function broke because it's saying or the yeah the definition here there's no test person uh i mean there's no birthday on this test person so what we need to do is we need to find that uh because we can when we're defining record types every part of the record type needs to be defined you can't have well you can't actually work there are ways to specify an optional uh way to do to provide something but you need to use an optional type or a maybe type or something to that effect but when it comes to other types like date date is not optional if we called it optional data would be but since it's not we need to actually give it a date so we can say okay well the date can be you know say the 20th of september and we can say 1980 um oh and we need to actually call this p t is the function date and so then that now type checks and now we've given this uh person who is not seven clearly because their birth date is in the 1980s um a birthday and then yeah if we wanted to be optional we could say you know optional date and we could work with the way optionals work to actually specify that but i'm not going to go into that it's just that when you're normally defining types everything needs to be defined so even in the case if this wasn't optional you would still have to define it as you know there is something here or there isn't something here and yeah so that's mostly how you do it but this one also goes into kind of how you would build a module and then how you would import it so i guess we could go ahead and do that so now we're now really looking at types we're looking at how we include modules in our files so we go ahead and we build our dar file out of um out of our code over here in our directory and so now what we need to do is we need to go ahead and point our demo.yaml file at it and so that's this line here is going to do that because here we can basically define all our dependencies and i'll show you the demo.yaml file in our ide here it is our dependencies it includes prim it includes std lib and demo trigger which is a service for doing actions download essentially responding to events but that'll be covered in another video and here we'll just include our dar file and then we can actually go ahead and import our address book from the dar file so we can go you know if we were to go to calendar and we decided hey we needed to include addresses in our calendar we can go ahead and import them and yes so that was basically a look at data types and imports they're you know super flexible they're really cool and interesting things to use they're fairly similar to in a lot of cases it's a haskell so if you're familiar with that um that's a great starting point but if you're not it's really quite it's really the same to learn as as any other language so i would say that you should definitely try it out and you know if you have questions we have discuss demo.com for our forum we obviously have all these lessons online and easily accessible for you to work through at your leisure and yeah we're always you know happy to answer questions and help out so yeah until next time thank you for watching my presentation on how to use data types and imports","transcript_synced_at":"2026-10-26T04:13:41.185Z","segments":[{"start_seconds":0,"text":"hi everybody uh we're actually starting a new series now my name is anthony i am a developer relation i do developer relations at","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=0s"},{"start_seconds":8,"text":"demo and today i'm going to be taking you through one of our online interactive tutorials","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=8s"},{"start_seconds":16,"text":"that's at demo.com learn you can see we actually have quite a lot of tutorials so in this series i'm going to be working through","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=16s"},{"start_seconds":24,"text":"them one by one it'll be similar to the other series where i went through the damn cheat sheet except this is a little more","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=24s"},{"start_seconds":31,"text":"in-depth and of course you know if you don't want to watch the videos and want to try these out yourself just go to donald.com","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=31s"},{"start_seconds":39,"text":"learn and you can start them up each and every one of these scenarios gives you a complete demo","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=39s"},{"start_seconds":47,"text":"platform essentially the entire demo ecosystem inside of your browser","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=47s"},{"start_seconds":54,"text":"so that you don't need to download anything you don't need to install anything everything just runs it works so what we're going to do today is we're going to do data types and imports","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=54s"},{"start_seconds":63,"text":"so we're going to learn about how functions work in demo records sums and how to import other packages and all","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=63s"},{"start_seconds":71,"text":"these very basic things with demo so this scenario says that it'll take about 30 minutes i feel like this video","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=71s"},{"start_seconds":79,"text":"is going to be a little less it'll probably be about 15 to 20 minutes so let's get started all right first we got to fire up our ide because","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=79s"},{"start_seconds":88,"text":"we're going to be doing a lot of things in that um but yeah one of the first things we're going to be doing is we're going to be looking at","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=88s"},{"start_seconds":95,"text":"essentially how we declare a type in demo and kind of uh then how do we assign a value to it","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=95s"},{"start_seconds":104,"text":"so right here we have our first type uh our first variable","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=104s"},{"start_seconds":113,"text":"and that is answer and it is of type integer and then we can assign a value to it and we can say answer is equal to 42.","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=113s"},{"start_seconds":124,"text":"uh this is basically since this is demo and it's a a functional language and i i'm not","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=124s"},{"start_seconds":131,"text":"using the term or not i didn't use the terminology fully correctly but this is actually a constant function which basically means that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=131s"},{"start_seconds":138,"text":"answer is always going to return 42 from now on and that's a very","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=138s"},{"start_seconds":146,"text":"basic basic type but we can have much more interesting types and functions so we're going to","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=146s"},{"start_seconds":154,"text":"define here a square and square is a function that takes an integer and gives you back another integer","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=154s"},{"start_seconds":162,"text":"and you can actually see that in the type definition here you have your first integer and then an arrow and it'll point to the","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=162s"},{"start_seconds":170,"text":"second integer so that's basically saying that the chain starts over here and the chain ends over here and what you","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=170s"},{"start_seconds":179,"text":"can basically infer from that is that you will take in a number and give out a number because","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=179s"},{"start_seconds":187,"text":"whatever is at the end of this so for example if there were three of them there's this one type check now but if there were three of them whatever's at","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=187s"},{"start_seconds":196,"text":"the end is what's going to be returned and the others are going to be arguments going into this function so for example to make that actually","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=196s"},{"start_seconds":203,"text":"work we could do you know squares x times y which of course it isn't so that would be something like","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=203s"},{"start_seconds":210,"text":"like multiply and then we have a function now that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=210s"},{"start_seconds":220,"text":"takes two integers and does something and returns an integer and as we're going to see it's actually very powerful see","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=220s"},{"start_seconds":229,"text":"these function definitions are very powerful because you can actually know quite a lot about the function itself","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=229s"},{"start_seconds":236,"text":"without reading what it does like you obviously still have to read what it does but you don't have to read what it does","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=236s"},{"start_seconds":244,"text":"all the time in order to kind of get an idea of what it is and also i'll show you later you","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=244s"},{"start_seconds":252,"text":"can even take that idea and say i need a function that does this like i know what this i'm not going i don't want to write this function but","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=252s"},{"start_seconds":261,"text":"i know that this function will take an integer and it'll take some text and it'll output some other text or something to that effect and you can","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=261s"},{"start_seconds":269,"text":"actually knowing what you want your function to look like you can actually then go and look up your function","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=269s"},{"start_seconds":276,"text":"in something called hugo that we use at demo which is a pre based on uh","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=276s"},{"start_seconds":284,"text":"haskell's hugel search engine where you can basically say i have a function that or i want a function and i want it to be","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=284s"},{"start_seconds":293,"text":"do this thing i wanted to take these arguments and give back this argument and then you can go and look that up which is really really cool when you're","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=293s"},{"start_seconds":301,"text":"when you're trying to find out what the thing you want to do is called without having to go and regularly google it","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=301s"},{"start_seconds":309,"text":"but anyway we can have you know more advanced functions yet again like i demonstrated before with the multiply","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=309s"},{"start_seconds":318,"text":"example where i turn square into multiply here we have a function that can do diagonals and this one you know it'll take","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=318s"},{"start_seconds":325,"text":"two decimals and it'll output another decimal and yeah so that's really cool so","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=325s"},{"start_seconds":334,"text":"knowing all that we know now especially knowing what we know about function definitions how can we answer this question and the question says you","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=334s"},{"start_seconds":343,"text":"know which of the following uh is the type of a function that returns the number of occurrences of a given character in a given string","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=343s"},{"start_seconds":351,"text":"okay so looking at this question we want the number of occurrences of a given character in a given string so","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=351s"},{"start_seconds":359,"text":"we know we want our function to contain three things we want our function to return a number which would probably be an","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=359s"},{"start_seconds":367,"text":"integer since characters can occur half of a time or any any fraction of a time like that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=367s"},{"start_seconds":376,"text":"uh we also know that we want it to be a string to figure out what character","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=376s"},{"start_seconds":384,"text":"how many of those characters are in a string and it's returning the integer okay so we have then essentially just one option here where","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=384s"},{"start_seconds":392,"text":"we have the character and a string that we're going to give into it and it's going to give us back an integer that sounds a lot like what","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=392s"},{"start_seconds":400,"text":"we would want and i'm not actually sure if this one's in hugo but let's go find out","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=400s"},{"start_seconds":407,"text":"so just to demonstrate here go to google.donald.com and we say oh we okay so that one","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=407s"},{"start_seconds":415,"text":"doesn't exist so there is no function presently in demo that will do that for us but if we wanted to work on an into an end","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=415s"},{"start_seconds":424,"text":"we could look that up and fund them and i'll probably find a better example as we go through this but that's just kind of what you can do is you can","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=424s"},{"start_seconds":432,"text":"go and take these types that you know about and say oh hey i want to take an integer and i want to output it as text","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=432s"},{"start_seconds":441,"text":"how can i do that and then oh i have this where i can take lots of things and i'll","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=441s"},{"start_seconds":446,"text":"put them as text maybe that'll work and let me go back here","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=446s"},{"start_seconds":456,"text":"okay so now we've we've done that and now we also want to actually use diagonal and try it out there are","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=456s"},{"start_seconds":463,"text":"several ways we could do this because we need to answer this question of diagonal what's a diagonal of three four","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=463s"},{"start_seconds":472,"text":"uh we have several ways we could you know go ahead and use the download repo we could use demo script which is","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=472s"},{"start_seconds":480,"text":"uh the way you're recommended to start doing things with demo when you want to do operations on a ledger and and do","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=480s"},{"start_seconds":488,"text":"tests and setup and tear down but right now i'm just going to use scenarios which is the previous version um i don't believe our catacota version","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=488s"},{"start_seconds":497,"text":"yet has script in it but by the time you're watching this video it probably will have scripts which is actually very similar just a bit","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=497s"},{"start_seconds":504,"text":"different and a bit more powerful and a bit more consistent but anyway let me go ahead and uh write out our scenario","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=504s"},{"start_seconds":514,"text":"so we write out scenarios by saying scenario do and then what we're going to do is we're going to take our diagonal","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=514s"},{"start_seconds":522,"text":"and we're going to say diagonal 3.0 4.0","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=522s"},{"start_seconds":529,"text":"and just return it okay and then we can actually run our","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=529s"},{"start_seconds":537,"text":"scenario in","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=537s"},{"start_seconds":539,"text":"our in our browser here and this is actually you know it's starting up a demo sandbox","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=539s"},{"start_seconds":547,"text":"it's actually processing everything and then it's returning the values and so we could see right here we've got our return value of 4.999","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=547s"},{"start_seconds":556,"text":"uh pretty sure that rounds up to five so let's select five and continue hooray we got you got the answers","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=556s"},{"start_seconds":565,"text":"correct so then moving on you know we have lots of other interesting types too that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=565s"},{"start_seconds":573,"text":"we can use in donald that are also fairly similar to what you would find in haskell and one of the most basics is a record","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=573s"},{"start_seconds":581,"text":"type so what a record type does is it allows you to take a variety of different data","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=581s"},{"start_seconds":587,"text":"and put it together so that it forms a cohesive hole so rather than saying you know","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=587s"},{"start_seconds":594,"text":"having street of type text and then city of type text","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=594s"},{"start_seconds":602,"text":"like these two things we know that they go together so if they go together we can just","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=602s"},{"start_seconds":609,"text":"make a record type and here we have this record type that stores an address and it stores a street city and country and then we also","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=609s"},{"start_seconds":618,"text":"have a very interesting and useful addition here that if you use haskell you'd also be aware of","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=618s"},{"start_seconds":626,"text":"is we can derive a lot of things here so that these record types can be used in other ways with other functions","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=626s"},{"start_seconds":633,"text":"just as a given so uh we can basically say you know deriving equality and show","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=633s"},{"start_seconds":640,"text":"and so what this basically does is it makes it so that we can now test for equality across our record types so we","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=640s"},{"start_seconds":648,"text":"can see if two addresses match each other um and we can also show them which means we can","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=648s"},{"start_seconds":655,"text":"make a text representation of all of them uh since demo is based on haskell it has this very powerful type system where it","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=655s"},{"start_seconds":662,"text":"essentially can go and say okay i know how to print text uh on a screen and i know how to","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=662s"},{"start_seconds":672,"text":"convert an integer to text i know how to convert a decimal to text okay i can just show those without you having","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=672s"},{"start_seconds":680,"text":"to write code to say this is how you do it and it's also important in within demo for record types to","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=680s"},{"start_seconds":689,"text":"have uh a quality and show on them because then that means you can use them in most","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=689s"},{"start_seconds":696,"text":"other parts of demo particularly when we're writing templates as i'll show you later we need to have","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=696s"},{"start_seconds":705,"text":"those those uh those type classes on on these record types","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=705s"},{"start_seconds":713,"text":"in order to make sure that that that the template can actually handle them because if we remove them then it","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=713s"},{"start_seconds":721,"text":"wouldn't but just really really uh specific stuff just know that whenever","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=721s"},{"start_seconds":729,"text":"you want to actually use a record type in demo you should be deriving eq and show and so here we have another record","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=729s"},{"start_seconds":737,"text":"showing that records can actually be nested here we have a person that can have a name and an address and that address","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=737s"},{"start_seconds":744,"text":"obviously corresponds to this record type so they can contain that and then we within that person you know we can store all these records and then","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=744s"},{"start_seconds":752,"text":"their address is also a record within their record uh again you know if we want to we can go ahead and we can say deriving","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=752s"},{"start_seconds":761,"text":"eq and show and since we demo knows how to print and test for equality on say an integer and also an address","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=761s"},{"start_seconds":769,"text":"as a result of deriving them over here it can go ahead and just derive that again for itself and so if we were to create","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=769s"},{"start_seconds":778,"text":"a record we would go ahead and do something like this where we would essentially say okay here's our person","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=778s"},{"start_seconds":786,"text":"that's their address the city country age and so on uh you know very basic but this is just the","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=786s"},{"start_seconds":795,"text":"syntax you would use it looks quite similar to jason","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=795s"},{"start_seconds":803,"text":"and then once we've actually gone ahead and done this we have several different ways that we can","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=803s"},{"start_seconds":810,"text":"pattern match and access different parts of the of the record","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=810s"},{"start_seconds":818,"text":"so for example here we have a function that pre-prints somebody's address and the way they can do it","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=818s"},{"start_seconds":826,"text":"is by using positional arguments because we know street occurs first city occurs second and country occurs third we can say","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=826s"},{"start_seconds":835,"text":"we're working on address types and we're taking things out of these positions and then printing them the problem with that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=835s"},{"start_seconds":842,"text":"particular approach is that if you have something where say city","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=842s"},{"start_seconds":850,"text":"is first now it's going and the types still match now we're going to end up in a situation where","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=850s"},{"start_seconds":857,"text":"city and street are in the wrong order down over here so that's not good so there are other ways to do this that i would actually recommend doing over","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=857s"},{"start_seconds":866,"text":"this this particular approach but this is definitely one useful way you can do it uh especially in cases where you're","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=866s"},{"start_seconds":874,"text":"working with something that things that might not be named like tuples but the other way that i would recommend","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=874s"},{"start_seconds":881,"text":"doing most of the time especially for record types is to go ahead and use the field accessor so you can","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=881s"},{"start_seconds":889,"text":"say oh address.street address.city and now when these things are moved like cities up here it doesn't affect it","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=889s"},{"start_seconds":897,"text":"so yeah now we have a few questions so first and foremost you know what would the following return","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=897s"},{"start_seconds":905,"text":"testperson.age we can kind of look and say it would be seven and then what will the following return if we were to pretty print","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=905s"},{"start_seconds":914,"text":"the address we can go ahead and run that really quickly","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=914s"},{"start_seconds":924,"text":"steeple scenario do and we'll just run that and we should","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=924s"},{"start_seconds":933,"text":"turn this oh also not really part of this lesson but you'll sometimes see me using these dollar signs","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=933s"},{"start_seconds":941,"text":"dollar signs are essentially shorthand for do everything to the right of this first and then do the stuff to the left uh you can think of them as equivalent to","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=941s"},{"start_seconds":950,"text":"using parentheses around around uh around different parts of of your functions","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=950s"},{"start_seconds":957,"text":"and does the same exact thing so we'll run it and get our results okay we can see our return value screen is a little small here so forgive","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=957s"},{"start_seconds":966,"text":"me but that should be our return value for when we run that function and it does exactly what we would expect it to do you know it","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=966s"},{"start_seconds":975,"text":"goes ahead and it get prints the street separates it city separates it by some text country perfect","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=975s"},{"start_seconds":984,"text":"and so basically what we can then do is we can go ahead and","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=984s"},{"start_seconds":992,"text":"use these record types in templates and what what it says right here what my co-worker robin wrote when he was","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=992s"},{"start_seconds":1001,"text":"creating this example is that we can essentially think of a template as a record type but with some other things on it you know it has parties and signatories","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1001s"},{"start_seconds":1010,"text":"it tells you who's observing the contract who can use it and do what with the contract and that's","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1010s"},{"start_seconds":1017,"text":"you know super super interesting in that uh can really just treat these things","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1017s"},{"start_seconds":1026,"text":"fairly similarly and we can we can just kind we can","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1026s"},{"start_seconds":1034,"text":"really if you know if you know record types from haskell you can kind of just imagine a template as a record type that is simply going to be a record type that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1034s"},{"start_seconds":1043,"text":"will commit itself and store itself somewhere so record types themselves like if you make just date a person and you run your program","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1043s"},{"start_seconds":1052,"text":"if you're not saving it anywhere you're not really committing it anywhere and you're not really setting any rules on it what templates are are basically record types that you can","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1052s"},{"start_seconds":1060,"text":"easily commit to a ledger or some sort of database and that you can actually set more permissions and rules around","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1060s"},{"start_seconds":1068,"text":"which is very interesting and yes so just to demonstrate too if we remove the","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1068s"},{"start_seconds":1078,"text":"deriving uh and the eq and show we oh sorry i should remove the whole","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1078s"},{"start_seconds":1085,"text":"thing what we might end up with is oh never mind i removed it from the wrong","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1085s"},{"start_seconds":1092,"text":"one that's why that wasn't working if we removed arriving just to demonstrate what i was talking about","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1092s"},{"start_seconds":1100,"text":"before we now see that our our template can no longer use","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1100s"},{"start_seconds":1108,"text":"our record type and so here the type checker is actually very helpful it'll tell us","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1108s"},{"start_seconds":1115,"text":"oh you should use a deriving instance because we can't derive an instance for equality on the person contract","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1115s"},{"start_seconds":1123,"text":"because address doesn't have a quality and then it'll show you the same thing for show it'll say we can't","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1123s"},{"start_seconds":1131,"text":"you know we don't know how to print this um we don't know how to turn this into text so can can can you derive","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1131s"},{"start_seconds":1139,"text":"this and it basically is saying go ahead and add deriving to it and then we can go and and test out some","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1139s"},{"start_seconds":1147,"text":"things so oops let's call this test two so the name doesn't conflict","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1147s"},{"start_seconds":1155,"text":"and here where you know we're just going ahead and creating a person contract on our on our ledger and we can see that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1155s"},{"start_seconds":1162,"text":"they now exist and now this is very similar to the record type except rather than just being stored in memory and then later forgotten and this","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1162s"},{"start_seconds":1171,"text":"is actually something that's been committed to a ledger this ledger in particular of course is in memory but many many ledgers and databases also","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1171s"},{"start_seconds":1180,"text":"will just write to disk so yeah anyway we answered the quiz correction","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1180s"},{"start_seconds":1188,"text":"we answered the quiz questions correctly up above i believe so let's move on to the next thing the okay so our next very fun data type","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1188s"},{"start_seconds":1198,"text":"is enumerations these are very similar to enumerations that you would find in many","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1198s"},{"start_seconds":1206,"text":"other languages basically you have this data that can be one of several different things","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1206s"},{"start_seconds":1212,"text":"and you can go ahead and specify them so here we've defined gender and then you know we want to extend our gender function to allow","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1212s"},{"start_seconds":1221,"text":"other genders to be specified in a in a general sense and then we can go ahead and say okay now our options are m f","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1221s"},{"start_seconds":1229,"text":"and other and you can provide text for for that other option you know you can also extend these so that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1229s"},{"start_seconds":1236,"text":"you have all them all sorts of genders included uh this is just kind of showing too that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1236s"},{"start_seconds":1244,"text":"you know you can have this enumerative type but your enumerative type also is","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1244s"},{"start_seconds":1252,"text":"able to enumerate not just that to that specific type that mf but it can actually contain","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1252s"},{"start_seconds":1259,"text":"other types within it so you can even for example you could add text to any of these so you can add qualifiers for","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1259s"},{"start_seconds":1268,"text":"all these and then work on them i don't think the way these functions are defined here is going to actually you know what we'll","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1268s"},{"start_seconds":1277,"text":"leave one it'll throw some errors but then we'll show how how that works so here we have our type and then what we can do","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1277s"},{"start_seconds":1285,"text":"too is we can go ahead and handle all those cases so for handling cases of these","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1285s"},{"start_seconds":1293,"text":"options we can go ahead and say okay well what we want to do is we want to is we want to print these things so","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1293s"},{"start_seconds":1301,"text":"we can say here's how we're going to handle our cases and it's going to also make sure we handle all of our cases or that if we don't we can","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1301s"},{"start_seconds":1309,"text":"have a case where we handle all other cases that we we weren't interested in so for example","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1309s"},{"start_seconds":1316,"text":"here we're getting a bit of an error and i'll go into that in a second but we can say okay in case of m","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1316s"},{"start_seconds":1324,"text":"we're going to print mail in case of f we're going to print female in case of other we're going to print o which is which is that text attached to other","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1324s"},{"start_seconds":1332,"text":"but male also has a text attached to it here so in order to in order to deal with that what we can do is if we weren't interested in the text","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1332s"},{"start_seconds":1341,"text":"we can say bottom and what that basically does is that lets us discard uh that text there","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1341s"},{"start_seconds":1348,"text":"because we weren't interested in in printing it the other way we could do that too is we can you know we could assign it as as a","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1348s"},{"start_seconds":1358,"text":"give it a variable but we just wouldn't use it but in general the the best way to do it is that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1358s"},{"start_seconds":1365,"text":"and then for example if we wanted to you know uh just print","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1365s"},{"start_seconds":1377,"text":"if we wanted to just handle any particular case we can do this and we can say you know bottom","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1377s"},{"start_seconds":1385,"text":"any of these types we should just print some text and that's it um yeah so that's the that's the way you","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1385s"},{"start_seconds":1394,"text":"would handle those different cases of having these of enumerating these things","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1394s"},{"start_seconds":1402,"text":"anyway i need to just reset that so that when we run our functions we'll get the right thing okay so if we do","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1402s"},{"start_seconds":1410,"text":"pretty genzer m we can it'll go ahead and return mail and then if we were","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1410s"},{"start_seconds":1418,"text":"put hello world as a text it would return that so we can go ahead there","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1418s"},{"start_seconds":1427,"text":"so now with our the next thing we can work on is type synonyms uh what this essentially means","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1427s"},{"start_seconds":1434,"text":"is that when we're working with these types we don't","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1434s"},{"start_seconds":1441,"text":"always want it to be an integer for example so here's a great example is uh","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1441s"},{"start_seconds":1449,"text":"a phone number when when we have a phone number you know we might represent it as text or an integer or something to","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1449s"},{"start_seconds":1458,"text":"that effect but we don't want to call it just text because it's not just text it has other meaning to it and so what we do here","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1458s"},{"start_seconds":1466,"text":"is we say you know okay we're taking a phone number and then we're printing some text","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1466s"},{"start_seconds":1474,"text":"and we're basically saying you know our we've gone","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1474s"},{"start_seconds":1482,"text":"ahead though and said oh our phone number is actually a type and the type is actually integer so integer and phone number are","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1482s"},{"start_seconds":1490,"text":"now equivalent to each other if you have a function that works on an integer i believe it'll work on a","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1490s"},{"start_seconds":1497,"text":"phone number let me just check that really quick","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1497s"},{"start_seconds":1512,"text":"um","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1512s"},{"start_seconds":1522,"text":"a pretty phone number","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1522s"},{"start_seconds":1529,"text":"yep it'll work so yeah essentially they if you have any function that works on an integer","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1529s"},{"start_seconds":1537,"text":"it also work on a phone number now because they are the same we're just using that that type name as a convenience so that we're","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1537s"},{"start_seconds":1547,"text":"much more informative as to what type of data we're really really working on","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1547s"},{"start_seconds":1552,"text":"so let me just delete this here okay and","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1552s"},{"start_seconds":1561,"text":"so the other thing we can do too is we can go ahead and uh","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1561s"},{"start_seconds":1568,"text":"change the phone number to actually be a variety of data and so what we can say is","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1568s"},{"start_seconds":1575,"text":"oh we want our phone number to be not just an integer because just an integer is not enough","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1575s"},{"start_seconds":1582,"text":"data to represent everything so we can do here is we can have","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1582s"},{"start_seconds":1588,"text":"uh it be another it be a data type it'd essentially be a record type and we can do","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1588s"},{"start_seconds":1597,"text":"we can we can have you know the variety of different digit groups and then we can go ahead and you know represent those in much the","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1597s"},{"start_seconds":1604,"text":"same way we represented addresses when we were pretty printing them","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1604s"},{"start_seconds":1612,"text":"and so yeah you can also go ahead and import your own modules so what this basically means is","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1612s"},{"start_seconds":1621,"text":"that you know if you have fairly common functions much like you would in any other language you can put them","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1621s"},{"start_seconds":1628,"text":"in a module and then go ahead and import them in this case you would be able to say go ahead and import address book","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1628s"},{"start_seconds":1636,"text":"um i won't work through this particular part in too much detail but if you want to try it out yourself you can go ahead","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1636s"},{"start_seconds":1644,"text":"and check out the editor and you can then go and take your address book take your data and","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1644s"},{"start_seconds":1652,"text":"put everything that's common into you know your your library and then go ahead and import that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1652s"},{"start_seconds":1659,"text":"and you also have a variety of ways to import data so you can import data very specifically you can say","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1659s"},{"start_seconds":1666,"text":"i want to import things but i only want to import these things from from address book like i only want to import address i don't","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1666s"},{"start_seconds":1675,"text":"want to import personally because i'm not using the person representation on things or you can say okay well i want to","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1675s"},{"start_seconds":1682,"text":"import dress book but i want to do a qualified import i want to go ahead and import it you know as a so then i can refer to","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1682s"},{"start_seconds":1691,"text":"the person in and addressing them as a.person and a dot address instead of just importing them at the higher level","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1691s"},{"start_seconds":1699,"text":"it's very useful too when you want to you know when you're working with a lot of different libraries um qualified imports","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1699s"},{"start_seconds":1706,"text":"do come in handy very often in demo and so we have a couple more questions","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1706s"},{"start_seconds":1714,"text":"here so which of the following function types will be in scope after the import statement import address book this is a tricky question too i actually i","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1714s"},{"start_seconds":1722,"text":"answered this one before it was a little tricky uh the answer is actually most of these things so the constructor that actually puts","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1722s"},{"start_seconds":1731,"text":"together the address will be it uh the address type and so what i mean by that is your constructor is over here","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1731s"},{"start_seconds":1738,"text":"basically says how the address is formed how it's constructed uh and then your type is over here basically says","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1738s"},{"start_seconds":1746,"text":"okay this is this this is the address type and so this is just something to keep in mind is","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1746s"},{"start_seconds":1754,"text":"that you know when you say a data address equals address that sounds kind of redundant but it's there for a reason because one is the type","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1754s"},{"start_seconds":1762,"text":"and one is the constructor for that type and so the other things that are available are street obviously city","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1762s"},{"start_seconds":1770,"text":"country look up is not available but length is and that's why this was a tricky question because length is always","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1770s"},{"start_seconds":1778,"text":"available it's part of the prelude endemol um if you're coming from a high school background that's the same as the prelude in","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1778s"},{"start_seconds":1786,"text":"haskell it is the portion of the library that's always imported so","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1786s"},{"start_seconds":1792,"text":"the for very common functions like length there and there and then","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1792s"},{"start_seconds":1799,"text":"okay which of the following function types will be in scope after the import statement import qualified address book as a well a","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1799s"},{"start_seconds":1807,"text":"dot address the type should be a dot street should be and length should be let's see if i've","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1807s"},{"start_seconds":1814,"text":"answered those correctly yep i did yay okay and then yeah so the same way you could","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1814s"},{"start_seconds":1823,"text":"import your own your own libraries your own modules uh demo also lets you import demo also comes with a lot of a","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1823s"},{"start_seconds":1832,"text":"very useful modules so for example you know you have da.date so if you wanted to import da.date","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1832s"},{"start_seconds":1842,"text":"you can go ahead and do it here and then you could say okay","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1842s"},{"start_seconds":1848,"text":"we want oh not an address we want to add a birthday to this type","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1848s"},{"start_seconds":1856,"text":"of person and then we can say their birthday we're going to have it be a date and so once we do that though we can actually","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1856s"},{"start_seconds":1865,"text":"see that our some of our other functions broke um in particular the test person","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1865s"},{"start_seconds":1873,"text":"function broke because it's saying or the yeah the definition here there's no test person uh i mean there's no","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1873s"},{"start_seconds":1882,"text":"birthday on this test person so what we need to do is we need to find that uh because we can when we're defining record types every","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1882s"},{"start_seconds":1890,"text":"part of the record type needs to be defined you can't have well you can't actually work there are ways to specify an","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1890s"},{"start_seconds":1898,"text":"optional uh way to do to provide something but you need to use an optional type or a","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1898s"},{"start_seconds":1905,"text":"maybe type or something to that effect but when it comes to other types like date date is not","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1905s"},{"start_seconds":1912,"text":"optional if we called it optional data would be but since it's not we need to actually give it a date so we can say okay well the date can be","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1912s"},{"start_seconds":1921,"text":"you know say the 20th of september and we can say 1980 um oh and we need to actually call this","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1921s"},{"start_seconds":1928,"text":"p t is the function date and so then that now type checks and now we've","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1928s"},{"start_seconds":1935,"text":"given this uh person who is not seven clearly because their birth date is in the 1980s um a birthday and","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1935s"},{"start_seconds":1944,"text":"then yeah if we wanted to be optional we could say you know optional date and we could work with the way optionals work to actually","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1944s"},{"start_seconds":1952,"text":"specify that but i'm not going to go into that it's just that when you're normally defining types everything needs to be defined so even in the case","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1952s"},{"start_seconds":1960,"text":"if this wasn't optional you would still have to define it as you know there is something","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1960s"},{"start_seconds":1967,"text":"here or there isn't something here and yeah so that's mostly how you do it","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1967s"},{"start_seconds":1978,"text":"but this one also goes into kind of how you would build a module and then how you would import it so i guess we could go","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1978s"},{"start_seconds":1987,"text":"ahead and do that so now we're now really looking at types we're looking at how we include modules in our files so","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1987s"},{"start_seconds":1995,"text":"we go ahead and we build our dar file out of um out of our code over here in our","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=1995s"},{"start_seconds":2003,"text":"directory and so now what we need to do is we need to go ahead and point our demo.yaml file at it and so that's","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2003s"},{"start_seconds":2011,"text":"this line here is going to do that because here we can basically define all our dependencies and i'll show you the demo.yaml file in our ide","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2011s"},{"start_seconds":2021,"text":"here it is our dependencies it includes prim it includes std lib and demo trigger","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2021s"},{"start_seconds":2028,"text":"which is a service for doing actions download essentially responding to events but that'll be covered in another video","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2028s"},{"start_seconds":2036,"text":"and here we'll just include our dar file and then we can actually go ahead and import our address book","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2036s"},{"start_seconds":2044,"text":"from the dar file so we can go you know if we were to go to calendar and we decided hey we needed to include addresses in our calendar we can go","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2044s"},{"start_seconds":2052,"text":"ahead and import them and yes so that was basically a look at data types and imports they're you know super flexible they're really","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2052s"},{"start_seconds":2062,"text":"cool and interesting things to use they're fairly similar to in a lot of cases it's a haskell so if you're familiar with that","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2062s"},{"start_seconds":2070,"text":"um that's a great starting point but if you're not it's really quite","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2070s"},{"start_seconds":2076,"text":"it's really the same to learn as as any other language so i would say that you should definitely try it out and you","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2076s"},{"start_seconds":2084,"text":"know if you have questions we have discuss demo.com for our forum we obviously have all these lessons online and easily","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2084s"},{"start_seconds":2092,"text":"accessible for you to work through at your leisure and yeah we're always you know happy to answer questions and help out","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2092s"},{"start_seconds":2098,"text":"so yeah until next time thank you for watching my presentation on how to use data types and imports","url":"https://www.youtube.com/watch?v=GsWGxQbcYsw&t=2098s"}],"youtube_url":"https://youtube.com/watch?v=GsWGxQbcYsw","url":"https://ccpedia.xyz/videos/GsWGxQbcYsw"}