WEBVTT 00:00.300 --> 00:00.740 Welcome. 00:01.500 --> 00:05.030 Until now, you have learned a lot of things about the gold type system. 00:05.930 --> 00:12.290 Yet there are still many things that we need to talk about, so now here is the next thing that you 00:12.290 --> 00:12.870 need to learn. 00:13.040 --> 00:14.420 The unnamed types. 00:15.400 --> 00:21.190 By the way, if you want to understand this lecture correctly, then you should watch the previous call 00:21.190 --> 00:22.620 type system lectures. 00:23.410 --> 00:26.170 If you didn't watch them yet, please do so now. 00:26.530 --> 00:27.070 All right. 00:27.070 --> 00:27.770 Let's get started. 00:28.960 --> 00:34.000 Let's first learn what an unnamed type is, here's an error with three elements. 00:34.840 --> 00:38.260 The interesting thing here is that this is an unnamed type. 00:38.920 --> 00:44.170 This means a type definition hasn't defined it, so it doesn't have a name. 00:44.920 --> 00:46.210 Here is a quick question for you. 00:46.720 --> 00:49.270 What is the underlying type of this area? 00:49.900 --> 00:51.760 Please post a video and think about it. 00:57.960 --> 00:59.130 All right, I'm back. 01:00.200 --> 01:07.400 This area is on the line type is, well, itself, so it's underlying type is this three Endara type, 01:08.030 --> 01:08.960 but why? 01:09.820 --> 01:18.430 Remember, an underlying type has a real structure, so here this array literally defines its own size 01:18.430 --> 01:20.470 and its own representativity. 01:20.590 --> 01:21.000 Right. 01:21.460 --> 01:26.560 I mean, it defines a unique memory without which is consisting of three elements. 01:27.670 --> 01:32.010 It has literally defined the new modern unnamed type on the fly. 01:33.330 --> 01:40.290 And lastly, this is not only true for errors, it's also true for all the other composite types. 01:40.980 --> 01:42.550 We learn about them afterwards. 01:42.680 --> 01:43.080 Our. 01:44.620 --> 01:50.540 Now, let's take a look at a name type, this type definition creates a new array type with a new name. 01:51.220 --> 01:53.900 So the name of this type is Bookcase. 01:54.490 --> 01:55.870 Here is another question for you. 01:56.050 --> 01:58.990 What is the underlying type of the bookcase type? 01:59.440 --> 02:01.470 Police post video and think about it. 02:06.710 --> 02:14.210 All right, it's on the line, time is three ain't right, so this bookcase type gets its type from 02:14.210 --> 02:16.610 this tree int unintegrated. 02:17.330 --> 02:20.720 OK, now let's create an error literal using this new type. 02:21.810 --> 02:26.750 This is an early trial, but I declared it with the book type, which is a name type. 02:27.210 --> 02:31.680 So this arrays type is not just treatment, its type is bookcase. 02:32.880 --> 02:39.460 Now, let's create another era with an unnamed three in type like this, can we compare these areas? 02:40.250 --> 02:40.890 What do you think? 02:41.190 --> 02:43.250 Please post a video and think about it again. 02:50.530 --> 02:52.450 Yes, we can do wonder why. 02:53.320 --> 02:56.020 It's because their underlying type is the same. 02:56.950 --> 03:03.880 So this means a value with an unnamed type can be compared to a value with a name type as long as they 03:03.880 --> 03:06.150 have identical underlying types. 03:06.700 --> 03:13.720 The opposite of this also true, their underlying type is identical because they have the same structure. 03:14.210 --> 03:16.730 They both contain three values. 03:17.200 --> 03:19.120 So you can't directly compare them. 03:19.300 --> 03:21.450 You don't need to convert them by yourself. 03:21.940 --> 03:25.090 It's because implicitly converts them for you. 03:26.190 --> 03:28.080 Let me show you one more example. 03:28.710 --> 03:35.010 Now I'm going to declare another type cabinet and now I'm going to create a new array using this cabinet 03:35.010 --> 03:35.340 type. 03:35.940 --> 03:37.100 Here is a question for you. 03:37.650 --> 03:39.900 Can we compare these array values? 03:40.380 --> 03:41.130 What do you think? 03:41.590 --> 03:43.730 Please past video and think about it again. 03:50.270 --> 03:54.380 Nope, we can't compare them, their underlying type is the same, right? 03:55.250 --> 03:57.250 So why we can't compare them? 03:58.280 --> 04:00.590 It's because their top names are different. 04:01.190 --> 04:06.610 Remember, a name type is always a different type than any other type. 04:06.860 --> 04:10.070 OK, but there is still a way to compare them. 04:10.400 --> 04:11.050 Let's take a look. 04:12.450 --> 04:14.540 So guess how we can compare them? 04:19.520 --> 04:26.360 Remember, their underlying type is the same, so we can convert a bookcase value to our cabinets value 04:26.360 --> 04:30.810 or a cabinet value to a book is value in addition to that. 04:30.830 --> 04:35.740 Now, we can also compare them is because those values have the same types. 04:35.750 --> 04:38.790 Now they both are bookcase values. 04:38.810 --> 04:44.630 Now, by the way, you can only convert them if they're underlying types are identical. 04:45.140 --> 04:50.000 I'm not going to talk about this again because I have already talked about this in the go type system 04:50.010 --> 04:50.890 section before. 04:51.650 --> 04:55.190 Now, let's take a look at what you learned so far in decoding Ed. 04:57.200 --> 05:02.990 Remember the previous example where I've been comparing two bookcases with different colors, blue and 05:02.990 --> 05:03.300 red. 05:04.100 --> 05:08.030 So now I'm going to declare two areas using unnamed types like this. 05:08.600 --> 05:13.430 First, I'm going to declare this blue array variable with five elements like this. 05:14.510 --> 05:15.140 Another one. 05:16.380 --> 05:17.640 OK, let's compare them. 05:18.550 --> 05:20.680 First, I'm going to type a message like this. 05:20.920 --> 05:22.000 Are they equal? 05:23.080 --> 05:26.710 Then I'm going to compare these variables if they are equal. 05:28.250 --> 05:29.540 I'm going to print this. 05:30.790 --> 05:32.590 Otherwise, I'm going to print this. 05:33.650 --> 05:37.630 All right, run, as you can see, they are equal. 05:38.270 --> 05:41.150 Let me also print them with their types like this. 05:42.120 --> 05:43.170 Bluebox. 05:44.820 --> 05:45.420 And the red. 05:46.820 --> 05:47.740 OK, let's run it. 05:49.020 --> 05:52.910 As you can see, they both are the same unnamed five injuries. 05:53.790 --> 05:56.310 All right, now I'm going to declare a new type. 05:56.610 --> 05:59.010 The first one is this bookcase type. 05:59.790 --> 06:01.530 So the bookcase is on the line. 06:01.540 --> 06:03.180 Time is five Eynesbury. 06:03.960 --> 06:06.300 Now, take a look at this blue variable here. 06:06.930 --> 06:09.990 I'm going to change its type to the bookcase type. 06:11.100 --> 06:13.150 That's right, it works. 06:13.170 --> 06:18.290 There are still comparable and they are equal because there underlying type is identical. 06:18.780 --> 06:21.280 Their underlying type is five in there. 06:22.200 --> 06:25.710 Notice also that none of the blue erase type is a name type. 06:26.220 --> 06:31.320 When I printed it gets printed as mean that bookcase instead of just five. 06:31.340 --> 06:38.310 It is because its type is bookcase, which is a name type, not an unnamed type like five entero. 06:39.590 --> 06:43.640 OK, now I'm also going to declare and their name to the cabinet. 06:44.840 --> 06:48.900 As you can see, these two types have the same underlying types, right? 06:49.640 --> 06:51.030 Let's try to compare them. 06:51.740 --> 06:56.090 Now, I'm going to change this unnamed area literal to the cabinet type like this. 06:56.840 --> 07:01.340 Check out the comparison blow go compiler has called an error. 07:01.740 --> 07:02.480 Let's check it out. 07:02.960 --> 07:07.010 It says the bookcase and the cabinet have different types. 07:07.460 --> 07:09.170 So there is a type mismatch here. 07:09.680 --> 07:15.080 This happens because a name type is always a different type than any other type. 07:15.110 --> 07:18.770 OK, let's fix it by converting one of them. 07:19.520 --> 07:23.030 Now I'm going to convert this blue array to the cabinet type like this. 07:24.090 --> 07:25.770 As you can see now, it works. 07:26.280 --> 07:30.090 Let's run it as a look, it says they are equal. 07:30.300 --> 07:31.920 Cool again. 07:31.950 --> 07:38.760 Also, notice the type names here, the blue iris type is bookcase, whereas the red iris type is cabinet. 07:38.970 --> 07:40.260 They are different types. 07:40.260 --> 07:41.490 They have different names. 07:41.640 --> 07:42.010 OK. 07:42.780 --> 07:47.860 However, if I convert one of them, let's say this red area to the bookcase type. 07:48.210 --> 07:49.860 Let's see what it would look like. 07:51.160 --> 07:57.330 Now, it seems like the rhetoric type has changed on the fly, now it's a bookcase, the cabinet, right? 07:57.730 --> 08:01.930 So whenever you convert a value, it's time to change it on the fly. 08:02.140 --> 08:04.380 This is also true for the other composite types. 08:04.930 --> 08:09.240 I told you that to convert them, they're Underland types should be identical. 08:09.250 --> 08:09.640 Right. 08:10.210 --> 08:16.050 So now I'm going to change these cabinet types on the line type to a 10 element interreg like this. 08:16.840 --> 08:18.840 Now, Gore has called an Arab. 08:19.600 --> 08:20.440 Let's check it out. 08:20.830 --> 08:27.330 It says that it cannot convert the value of the bookcase type to the cabinet, that it's because the 08:27.330 --> 08:29.080 underlying tab is different now. 08:29.770 --> 08:30.340 All right. 08:30.350 --> 08:31.330 Let me take this back. 08:31.870 --> 08:34.000 And Lussier, let me show you one more thing. 08:35.030 --> 08:40.310 Now I'm going to declare a new integer type like this, then I'm going to change the element type of 08:40.310 --> 08:41.990 the cabinet type like this. 08:42.920 --> 08:44.640 As you can see, there are errors. 08:44.660 --> 08:49.650 Now let's check it out, go cannot convert blue here to the cabinet type. 08:50.090 --> 08:50.780 But why? 08:51.910 --> 08:57.910 It's because now they're on the line, types are different, the cabinet type is on the line, type 08:57.910 --> 08:58.810 is not. 08:58.810 --> 09:01.450 Five isn't anymore, it is five. 09:01.660 --> 09:09.420 Integer is the name type but the underlying type of the integer and the int is the same, right? 09:10.120 --> 09:11.470 It is the same in type. 09:11.800 --> 09:15.280 So why they have different underlying types now. 09:17.020 --> 09:26.170 Remember, an unnamed type's on the line is itself here, five integer is an unnamed type, so it's 09:26.170 --> 09:29.990 underlying tab is itself, which is five integer. 09:30.670 --> 09:37.600 That's why five integer and five are different types there on the line types are different. 09:39.300 --> 09:40.950 Let me give you one more example. 09:43.430 --> 09:49.090 For example, here, this comparison is incorrect, it's because they have different underlying types, 09:49.760 --> 09:52.550 one is five integer, the other one is five int. 09:53.540 --> 09:54.530 But I can do this. 09:57.040 --> 10:03.430 This is because the cabinets on the laptop is five integer, remember, an unnamed type and a name type 10:03.430 --> 10:07.150 can be compared if they have identical underlying ties. 10:07.990 --> 10:10.210 So that's why I can compare them here. 10:11.130 --> 10:17.010 All right, that's all for now, as always, in the upcoming sections, you will understand this better. 10:17.520 --> 10:21.760 If you didn't understand it yet, please open this example and work on it. 10:21.780 --> 10:24.240 OK, do your own experimentations. 10:24.660 --> 10:30.450 By the way, the knowledge you have gained from this lecture will be very valuable in the upcoming lectures 10:30.450 --> 10:33.020 as well as in your real world go programs. 10:33.600 --> 10:39.960 And this is also important because it allows you to understand the gold type system in full detail. 10:40.470 --> 10:41.820 Thank you for watching so far. 10:41.940 --> 10:43.050 See in the next lecture.