 If you haven't been watching the videos on the Aida's type system in order, you need to because this is going to make absolutely no sense if you haven't seen the second part yet, and the second part really assumes that you've seen the first part. But today, we're going to be discussing tagged records, what a tagged record is, what it's used for, that kind of stuff. Now, quick rehash. Not enough if you haven't seen this though. We have a basic vehicle type, but it's not super descriptive, you know, a few properties, but it doesn't really do a good job of representing things better. And we can make it through a little bit of a object hierarchy, which is ultimately what tagged records are used for. Now, one little thing to note is I did bring my text library in here just so that I, at least for the numbers, when we print numbers out, I don't have to call Image on them anymore. So, let me get rid of limited for this. You can combine them. You can have a tagged limited record, but we're just going to remove it for now. Make this tagged. This will have to go. Oh yeah, this is a good point. This should actually be abstract. I believe it's abstract tagged record. And then we can't declare any of these. Let's remove these as well. And just make sure that's the right order. Let's see what we can expect. All right. No, there it is. Okay. So then from this, we can define new types like a car, not a cat, is a vehicle, is no vehicle. And then if you remember from last time, there's two little choices we can do for this. If we want to extend this further, we can do with record and then put in anything else. But if there's nothing else to extend this with, it's just null record. But there's an even better thing that I would do here. Instead of going straight to a car, instead do type land vehicle. What is that? Abstract new vehicle with null record. And you'll see in a bit why I'm doing this. We'll just check and make sure that I've got my order of words right. Because some of these are a little bit tricky. We do. Okay. And there's that. Oh, yes. Now that we've separated these out, we can... Yeah, I can move those now. If we do that. Now we won't have an issue with a water vehicle like a boat having tires. We can also extend this. Pillars natural. And default this to one. And no issues. Boat is no water vehicle. There's an important type of distinction each of these two vehicles can do. For example, a land vehicle can be driven. And one thing you want to ask yourself when you're doing these is this procedure or this function. Either way it would be a method in this case. Is this something that can reasonably operate on the class-wide or should each child of it implement its own drive method? In this case, we're going to ignore the concept of treads and also legged vehicles. Just to say that, well, they've all got tires. They're all going to drive the same way. And so you call it on a class-wide. This takes advantage of polymorphism so that if we have, say, both a car and a truck, or actually if we extend land vehicle to both be a car and a truck type so that both of them exist, either one of them would be able to use the drive method without needing to create another one because the only things it's concerned with are already defined in land vehicle. If we were to change it to, like, tired land vehicle versus treaded land vehicle, then we wouldn't be able to do this because they have different modes of being driven. Actually, I'm not going to show that off, but I'm not going to actually use that here because we're just going to do a simple function call just to sort of simulate this stuff. Excuse my ignorance, but I believe for boats and stuff, it's still called piloting. All right, these don't need to just be specs. We can just do the single line. I still have my text. Yeah, okay. So now we can just do this. What are you still complaining about? Line 17. Okay, those are just warning. That's fine. I can't hit car 35 and 36. Why would... But it's... I've never seen this problem before. Oh, wait, wait, wait, wait, wait, wait, because we declared these abstract and that... let's not do. Oh, totally the wrong thing. Oh, because I defined those as new types. Oh my God, oh my God. Okay, I paused this video, recording this video, waited a few days, and then just picked it back up again, so I'm sort of like trying to remember what I did and where I was going with this. Yeah, we'll get rid of these and then just call a car in the land vehicle. Color can be... we'll have a gray car. Now I have a green boat and then the others are fine. I used a wrong symbol on line 30. Yes, I did. Did I not define one of those for Boolean? I suppose that's possible. Got a sworn I did though. Oh, Boolean image. So then, obviously the types of vehicles are not just limited to land and water vehicles. We could define an air vehicle like a plane or a helicopter, but one of the more interesting things to try to show off is an amphibious vehicle because it's both a land and a water vehicle. It would make sense that in many cases you'd want to inherit from both of these. You can't. What it's really trying to say here is that because we already inherit from one tagged record all of the rest of them need to be interfaces because it can't appropriately figure out how to inherit from two tagged records. And the reason for this should be pretty obvious. At least with our current example, these two could be merged without conflict until you get into the what would normally be methods that operate upon them. These have the same names. These would result with the same signature. Which one of these do you use? And so if we wanted to actually define an amphibious vehicle, we have to go back, define it as a new type of vehicle with both tires. There are other types of amphibious vehicles, of course, but this we'll just use this example. Impropellers. But then this means that everything that would have been defined for land and water vehicle at a relevant need to be redefined for amphibious vehicle. That's against code reuse because you're duplicating code. Anything that's defined for vehicle will still work. But that's not going to be a whole lot given how abstract the base vehicle is. We can do basic things like repaint this, but a drive method would not really make sense on a base vehicle because driving a boat, how would you do that? Similarly, piloting around a land vehicle as if it was in the sky doesn't make sense. Piloting a base vehicle, which would include land vehicles, doesn't make sense. And you wouldn't want something like that to apply to an amphibious vehicle either. This is what's known as the diamond problem where you have one thing, let's call it D, that inherits from B and C. In this case, our B and C are land vehicle and water vehicle where both B and C inherit from vehicle or from A, which in our case is vehicle. If you were to graph this out, you will see a little diamond shape from the inheritance. I have basically shown off everything about tagged records that I want to show off. I'll do another video that's not really meant about how to declare and use the types, but much more in depth on tagged records and object-oriented programming, how to actually tell if something's dispatching or not and what that means, how to use class-wide types versus specific types and stuff like that in another video. This should be enough to really get you familiar with tagged records and how to declare them and use them. It also sets up for the next video because we're actually going to solve this diamond problem using something IDA has. So that's really cool. Not many languages have any type of facility to solve something like this without extensive code duplication. I'd like to remind you that these tagged records can be combined with other things that I've shown off or will show off. You can have discriminants at any point within these tagged records. So if we wanted to do the mode of the water vehicle based on propellers or wheels or whatever or the mode of the land vehicle based on tires or treads, you could implement that as a variant record, which again, we'll get into next time, but that sets up whether it's tires or tread-based. But you can also do that. At least in this example, it would be totally fine to do that through just another child type, inherit from land vehicle each time. But you can freely combine them. There's nothing that makes says a tag can't have a discriminant. Hope this video helps. If you like what I do, please give me a thumbs up. If you find my videos in general helpful, consider subscribing. Helps me out quite a bit more than YouTube makes obvious. But also consider hitting that little bell next to subscribe. It gives you notifications when I produce a new video, which is usually every day, every other day. Have a good one.