1
00:00:01,810 --> 00:00:03,399
welcome back everybody to

2
00:00:03,399 --> 00:00:06,629
FB 1 along functional programming and

3
00:00:06,629 --> 00:00:10,420
and today we're going to talk about
types and glasses

4
00:00:10,420 --> 00:00:15,059
as developers we often work

5
00:00:15,059 --> 00:00:20,430
all nighter we said and heck we got into
a flaw and we

6
00:00:20,430 --> 00:00:24,189
lose track of time and so for developers

7
00:00:24,189 --> 00:00:27,990
is extremely important to watch our diet

8
00:00:27,990 --> 00:00:31,580
to make sure that we eat well am

9
00:00:31,580 --> 00:00:34,950
if you she did food pyramid hear that

10
00:00:34,950 --> 00:00:38,239
the show in there and food

11
00:00:38,239 --> 00:00:44,290
is grouped into categories for example
you see Brad to rise and pasta

12
00:00:44,290 --> 00:00:48,190
which are carbohydrates and the UC

13
00:00:48,190 --> 00:00:53,329
and other things like brody each fruits
and vegetables

14
00:00:53,329 --> 00:00:56,789
et cetera so all foods

15
00:00:56,789 --> 00:01:00,340
is food into groups an

16
00:01:00,340 --> 00:01:04,729
that have a common property and in some
sense

17
00:01:04,729 --> 00:01:07,820
these groups what we can say is that

18
00:01:07,820 --> 00:01:11,760
the food here is typed an

19
00:01:11,760 --> 00:01:15,780
and that's what this lecture will be
about the lecture will be about

20
00:01:15,780 --> 00:01:19,530
taking values not food but the values
that we coat with

21
00:01:19,530 --> 00:01:23,390
and how do group these into categories

22
00:01:23,390 --> 00:01:27,860
that have similar properties so what is
it died

23
00:01:27,860 --> 00:01:31,560
%uh type is simply name

24
00:01:31,560 --> 00:01:35,869
for a collection %uh related values an

25
00:01:35,869 --> 00:01:39,140
just like and you know food group

26
00:01:39,140 --> 00:01:42,920
is a name for a collection of

27
00:01:42,920 --> 00:01:46,009
foods wit related properties

28
00:01:46,009 --> 00:01:50,430
and a dive is a name for a collection of
values that we go to it

29
00:01:50,430 --> 00:01:55,640
that have similar properties for example
and has called a dive ball

30
00:01:55,640 --> 00:01:59,259
an is a name for a collection

31
00:01:59,259 --> 00:02:04,090
that has two values false and true every
would be

32
00:02:04,090 --> 00:02:08,310
really really pedantic and has told
there would be a third

33
00:02:08,310 --> 00:02:11,450
value bottom and 83 percent

34
00:02:11,450 --> 00:02:11,909
and

35
00:02:11,909 --> 00:02:15,739
nom terminating computation of tribal

36
00:02:15,739 --> 00:02:19,709
but in this course as since we're going
to stick to the basics

37
00:02:19,709 --> 00:02:23,650
we will ignore and a more complicated
features

38
00:02:23,650 --> 00:02:27,700
like bottom so an for now

39
00:02:27,700 --> 00:02:30,950
we'll just say Bowl is a type

40
00:02:30,950 --> 00:02:34,760
that names this Sat with of values

41
00:02:34,760 --> 00:02:40,340
true and false values the bullying
values now

42
00:02:40,340 --> 00:02:46,220
type air is an something where we are
were using a function

43
00:02:46,220 --> 00:02:49,239
an with type: that

44
00:02:49,239 --> 00:02:54,099
the function does not expect am that's a
good example here

45
00:02:54,099 --> 00:02:58,750
you want to add Wong to false obviously

46
00:02:58,750 --> 00:03:02,000
that's not going to work because on the
left

47
00:03:02,000 --> 00:03:05,629
we have a number and on the right we
have a boolean

48
00:03:05,629 --> 00:03:09,299
and there's no way to add a number

49
00:03:09,299 --> 00:03:12,909
to a bully now and

50
00:03:12,909 --> 00:03:17,000
to go back to the an example of diet

51
00:03:17,000 --> 00:03:20,049
if you have a certain diet maybe

52
00:03:20,049 --> 00:03:23,260
you're not allowed to mix and I'll meet

53
00:03:23,260 --> 00:03:26,470
and dairy products so that would be a
TypeError

54
00:03:26,470 --> 00:03:29,730
in the food world and in their
programming world

55
00:03:29,730 --> 00:03:33,260
we have the same gonna I parish and

56
00:03:33,260 --> 00:03:38,799
the goal of static typing is that the
compiler will catch these type errors

57
00:03:38,799 --> 00:03:41,959
and early on before we run the program

58
00:03:41,959 --> 00:03:45,579
but there's also dynamically typed
languages where these type

59
00:03:45,579 --> 00:03:50,690
errors are and got at runtime so when
you're actually trying to

60
00:03:50,690 --> 00:03:53,709
and add up the Boolean

61
00:03:53,709 --> 00:03:56,859
and with the number and then there's a

62
00:03:56,859 --> 00:04:00,690
non typed languages where this will just
take

63
00:04:00,690 --> 00:04:03,909
well however these two values are
represented

64
00:04:03,909 --> 00:04:10,419
and will try to at them up the notation
the syntax

65
00:04:10,419 --> 00:04:14,150
for writing down types in Haskell is

66
00:04:14,150 --> 00:04:18,070
expression double go along type so if

67
00:04:18,070 --> 00:04:22,039
evaluating the expression E will produce

68
00:04:22,039 --> 00:04:25,150
a value of type T we ride today

69
00:04:25,150 --> 00:04:29,690
as he double column T other languages

70
00:04:29,690 --> 00:04:33,930
have different syntax for example Visual
Basic you a ride

71
00:04:33,930 --> 00:04:37,180
he St and in job on

72
00:04:37,180 --> 00:04:40,310
you would ride d easy and

73
00:04:40,310 --> 00:04:44,620
but that's all syntex shown in real
thing is that we're

74
00:04:44,620 --> 00:04:47,840
interested in the semantics of this
which as dead

75
00:04:47,840 --> 00:04:51,090
that type of expression the is T

76
00:04:51,090 --> 00:04:55,360
now every well-formed expression every

77
00:04:55,360 --> 00:04:59,290
and syntactically well-formed expression
has a type

78
00:04:59,290 --> 00:05:02,330
and that type is calculated

79
00:05:02,330 --> 00:05:06,260
an by the compiler and at compile-time

80
00:05:06,260 --> 00:05:09,580
using a a process called type in fridge

81
00:05:09,580 --> 00:05:13,130
an remember from the first lecture that

82
00:05:13,130 --> 00:05:17,450
and now the programming language and now
was one of the first programming

83
00:05:17,450 --> 00:05:18,180
languages

84
00:05:18,180 --> 00:05:23,610
with that had type infringe a TypeError

85
00:05:23,610 --> 00:05:27,520
are also and in Haskell found at
compile-time

86
00:05:27,520 --> 00:05:31,190
most and programming languages are found
at compile-time

87
00:05:31,190 --> 00:05:34,390
an and the you know

88
00:05:34,390 --> 00:05:39,240
the opinions about differ and whether
you know you have to have static typing

89
00:05:39,240 --> 00:05:42,330
or dynamic typing or optional typing

90
00:05:42,330 --> 00:05:46,170
and the two for me personally I like

91
00:05:46,170 --> 00:05:50,000
I'm lazy so I like if the compiler
catches the

92
00:05:50,000 --> 00:05:55,250
I Paris for me early and the previous
lecture we have played

93
00:05:55,250 --> 00:06:00,430
around GHz nghe has a special Kum & Go
long type

94
00:06:00,430 --> 00:06:04,720
that allows you do I asked did type of
an expression so you can

95
00:06:04,720 --> 00:06:09,530
ask GHz to calculated the type of an
expression for you

96
00:06:09,530 --> 00:06:15,250
so for example every type and not false
GHG will calculate the value of that

97
00:06:15,250 --> 00:06:17,310
show not falls Eagles true

98
00:06:17,310 --> 00:06:20,970
but we can also ask for that type of not
false

99
00:06:20,970 --> 00:06:25,100
and in which case it will not evaluates
that expressions

100
00:06:25,100 --> 00:06:29,720
but they will just be calculate its type
so did I but not false

101
00:06:29,720 --> 00:06:31,090
is bull

102
00:06:31,090 --> 00:06:34,480
and now we see that the value of not
Falls is true

103
00:06:34,480 --> 00:06:37,690
the diapers bull so that's consistent

104
00:06:37,690 --> 00:06:41,260
GHz did a good job it would be weird

105
00:06:41,260 --> 00:06:45,860
am wrong if the type of not falls would
be integers day

106
00:06:45,860 --> 00:06:50,380
but the value would be true so that this
cult type soundness

107
00:06:50,380 --> 00:06:54,560
which means that the type that the
compiler calculates

108
00:06:54,560 --> 00:06:58,850
corresponds madame value that this
expression has

109
00:06:58,850 --> 00:07:03,850
when you executed at runtime and Haskell

110
00:07:03,850 --> 00:07:07,960
and most programming languages there are
a number of base types

111
00:07:07,960 --> 00:07:11,010
so these are types that are built into
the language

112
00:07:11,010 --> 00:07:14,210
and in Haskell an there's a handful

113
00:07:14,210 --> 00:07:17,340
in already seen ball develop the type

114
00:07:17,340 --> 00:07:23,330
of a boolean value is TRUE FALSE then
there's the type of character showed it

115
00:07:23,330 --> 00:07:28,480
jar is the name up a set of values that
denote characters

116
00:07:28,480 --> 00:07:32,840
and show jar contains characters like
ABC

117
00:07:32,840 --> 00:07:38,040
a truck driver all Unicode characters
and there's the type of string

118
00:07:38,040 --> 00:07:42,190
which are strings of characters and we
will see later net in Haskell

119
00:07:42,190 --> 00:07:45,810
strings are really nothing more than a
list of characters

120
00:07:45,810 --> 00:07:51,170
so string an you could say it's not
really a base type

121
00:07:51,170 --> 00:07:55,690
because it's defined in terms of two
other base types strings and characters

122
00:07:55,690 --> 00:07:59,260
and as cool as unique

123
00:07:59,260 --> 00:08:03,650
a.m. are unique and by don't have
similar properties

124
00:08:03,650 --> 00:08:07,130
and that it has both end and integers so

125
00:08:07,130 --> 00:08:12,990
ends are fixed precision integers and
32-bit or 64-bit integers

126
00:08:12,990 --> 00:08:16,530
and then integer are arbitrary precision

127
00:08:16,530 --> 00:08:21,280
integers so you can compute defect Oreo
of 5 from third

128
00:08:21,280 --> 00:08:25,790
and if you use type Integer that will
take a long time

129
00:08:25,790 --> 00:08:29,080
but it will will not overflow like

130
00:08:29,080 --> 00:08:32,440
when you use and and then of course
there's float

131
00:08:32,440 --> 00:08:36,399
floating point numbers

132
00:08:36,399 --> 00:08:39,749
I mentioned when we talked about
characters I mentioned

133
00:08:39,749 --> 00:08:44,879
that strange really are lists of
characters and the type of lists

134
00:08:44,879 --> 00:08:49,920
is the first generic type or polymorphic
type

135
00:08:49,920 --> 00:08:52,990
an that we will see and Haskell

136
00:08:52,990 --> 00:08:58,189
analyst it is a sequence of values where
all the elements have the same type

137
00:08:58,189 --> 00:09:01,959
the first example here and

138
00:09:01,959 --> 00:09:05,490
is a list of three Boulange false true
and false

139
00:09:05,490 --> 00:09:10,990
an you see here that we denote to type
with colon colon and then the type

140
00:09:10,990 --> 00:09:16,269
and is list of bull one of the nice
features of Haskell

141
00:09:16,269 --> 00:09:19,819
that the syntax of types you see here
disinfection

142
00:09:19,819 --> 00:09:23,009
dives sorry this index values here

143
00:09:23,009 --> 00:09:27,899
on the left looks very similar to dish
index of types on the right

144
00:09:27,899 --> 00:09:31,459
so we use the same square brackets to

145
00:09:31,459 --> 00:09:35,709
and indicate a list of values and we
used the same

146
00:09:35,709 --> 00:09:38,759
square brackets to indicate the type so

147
00:09:38,759 --> 00:09:42,360
false true false has teibel an

148
00:09:42,360 --> 00:09:46,240
the second example there as a type has a
list

149
00:09:46,240 --> 00:09:50,980
of characters abcd and its dive is a
list of character

150
00:09:50,980 --> 00:09:55,769
and that's just the same string to
engender all

151
00:09:55,769 --> 00:09:59,429
the rule is that Fabregas 50

152
00:09:59,429 --> 00:10:02,709
list ft denotes the type of lists

153
00:10:02,709 --> 00:10:07,360
with salomon's of type T now

154
00:10:07,360 --> 00:10:12,040
notes that the type of the list this
doesn't say anything about it she likes

155
00:10:12,040 --> 00:10:16,620
so if we have list false true it as type
less simple

156
00:10:16,620 --> 00:10:20,699
and if we have the type ado value false
true false

157
00:10:20,699 --> 00:10:23,980
it also has teibel an

158
00:10:23,980 --> 00:10:27,429
and also the types of these an

159
00:10:27,429 --> 00:10:31,749
elements can be arbitrary as long there
as they're all the same

160
00:10:31,749 --> 00:10:34,769
so and lost example down here

161
00:10:34,769 --> 00:10:38,600
to as a slightly more complicated die
bitch list

162
00:10:38,600 --> 00:10:42,249
a blessed of characters so that's what
you see here

163
00:10:42,249 --> 00:10:45,370
list the list of characters and if you
look at the value

164
00:10:45,370 --> 00:10:48,220
you see that it contains too late

165
00:10:48,220 --> 00:10:51,149
of characters then where the list is
that

166
00:10:51,149 --> 00:10:54,940
all the elements must have the same type
but the length is

167
00:10:54,940 --> 00:10:58,579
unrestricted compare and contrast that
with

168
00:10:58,579 --> 00:11:02,279
to Paul's to Paul an there

169
00:11:02,279 --> 00:11:07,610
the type contains the length but def
values the types of values can be

170
00:11:07,610 --> 00:11:08,300
different

171
00:11:08,300 --> 00:11:11,730
so the first example here that's a

172
00:11:11,730 --> 00:11:15,459
to Paul of to bully ends true and false

173
00:11:15,459 --> 00:11:18,500
so they're easy to type this bull call
my bull

174
00:11:18,500 --> 00:11:22,699
it's not the list it would be a less the
dive would be less double

175
00:11:22,699 --> 00:11:25,970
about in this case it's a tuba love to
boo Lance

176
00:11:25,970 --> 00:11:29,220
true and false and the divers global

177
00:11:29,220 --> 00:11:33,889
now that second example there as type
Boult Charvel

178
00:11:33,889 --> 00:11:38,540
and what you see here is that it
contains three values

179
00:11:38,540 --> 00:11:41,810
one is it Boolean the second long

180
00:11:41,810 --> 00:11:45,000
is a character and that they're gone is
a billion again

181
00:11:45,000 --> 00:11:48,630
and that's reflected in the time
engender all

182
00:11:48,630 --> 00:11:52,600
if we have it up all of type T want to
TN

183
00:11:52,600 --> 00:11:56,750
that should I prefer to pull that has
and values

184
00:11:56,750 --> 00:12:00,600
of each respective type the wrong
obscurity

185
00:12:00,600 --> 00:12:04,819
so the diaper over to Paul

186
00:12:04,819 --> 00:12:08,300
and coach its size so true false are

187
00:12:08,300 --> 00:12:14,120
falls through their as at am a dive bull
Bulls are you see their data length

188
00:12:14,120 --> 00:12:17,199
of this to Paul is reflected in the type

189
00:12:17,199 --> 00:12:21,509
second on there there's three billion
show we see that the tubal has three

190
00:12:21,509 --> 00:12:25,970
body image an and the type of
devaluation

191
00:12:25,970 --> 00:12:30,110
is unrestricted show they can be mixed
and matched so in this case we have a

192
00:12:30,110 --> 00:12:31,060
double

193
00:12:31,060 --> 00:12:34,220
that contains a character

194
00:12:34,220 --> 00:12:39,660
and then as the second value ate up all
that has a boolean and a character

195
00:12:39,660 --> 00:12:43,019
and then the last example there is it up
all

196
00:12:43,019 --> 00:12:46,399
that has a boolean and analyst of
characters

197
00:12:46,399 --> 00:12:51,329
CC as a bully and here a bully and
through

198
00:12:51,329 --> 00:12:55,069
analyst of AB and we see that the type
there

199
00:12:55,069 --> 00:12:59,850
is bull and this tough jock so this is
the end of Part one

200
00:12:59,850 --> 00:13:03,160
about types and next we'll talk about

201
00:13:03,160 --> 00:13:06,680
functions since we're dealing with the
functional language

202
00:13:06,680 --> 00:13:10,770
functions are very important so we'll
spend

203
00:13:10,770 --> 00:13:14,279
a little bit of time zooming into
functions thank you

204
00:13:14,279 --> 00:13:15,690
and CPU after the break