1
00:00:01,520 --> 00:00:03,560
welcome everybody to the

2
00:00:03,560 --> 00:00:08,849
FB 101 from shell programming ok I'm
really happy that we can do this from

3
00:00:08,849 --> 00:00:12,820
as I'm ok with it exercises and
everything

4
00:00:12,820 --> 00:00:17,820
am and let's get started

5
00:00:17,820 --> 00:00:23,480
immediately an one thing that I wanted
to tell you before we get going

6
00:00:23,480 --> 00:00:28,160
is that this is a mocha about functional
programming that's what the title says

7
00:00:28,160 --> 00:00:33,090
FB 101 functional programming so this is
not a course on Haskell were using

8
00:00:33,090 --> 00:00:33,920
haskell

9
00:00:33,920 --> 00:00:39,379
as a functional language but we're not
learning to program has called per se

10
00:00:39,379 --> 00:00:42,469
let me tell you a little bit a fish
story

11
00:00:42,469 --> 00:00:46,000
I travel often are going to conferences

12
00:00:46,000 --> 00:00:49,200
effin courses et cetera and

13
00:00:49,200 --> 00:00:52,989
during those travels I have ample time
to watch TV

14
00:00:52,989 --> 00:00:57,520
and 1i I was set up internet channels

15
00:00:57,520 --> 00:01:00,770
and their Ross one of those survival
shows

16
00:01:00,770 --> 00:01:03,960
where and this guy was trying to make up

17
00:01:03,960 --> 00:01:07,340
camp at night and trying to make a fire

18
00:01:07,340 --> 00:01:10,939
but his matches were wet now

19
00:01:10,939 --> 00:01:14,030
he could have got not in panic at all

20
00:01:14,030 --> 00:01:17,250
my matches are wet I cannot make a fire

21
00:01:17,250 --> 00:01:20,680
but what he did instead is he took a
shelf on

22
00:01:20,680 --> 00:01:23,840
and this knife Anne an

23
00:01:23,840 --> 00:01:27,869
took the battery out of a cell phone
open the battery

24
00:01:27,869 --> 00:01:30,869
and then the battery started to combust

25
00:01:30,869 --> 00:01:35,220
and that's what he used to start a fire
and this is the same

26
00:01:35,220 --> 00:01:38,380
attitude that I want to teach you in
this course

27
00:01:38,380 --> 00:01:42,530
while we're learning to you do
functional programming using haskell so

28
00:01:42,530 --> 00:01:44,159
haskell our matches

29
00:01:44,159 --> 00:01:47,860
and when work you don't have much is
available

30
00:01:47,860 --> 00:01:52,049
you still can do functional programming
and sometimes you have to smash your

31
00:01:52,049 --> 00:01:52,950
cell phone

32
00:01:52,950 --> 00:01:58,320
and open your battery to start a fight
so don't think that this is about

33
00:01:58,320 --> 00:02:02,030
haskell per se we're going to teach
functional programming

34
00:02:02,030 --> 00:02:06,299
using hash alright let's get

35
00:02:06,299 --> 00:02:09,869
started an a.m.

36
00:02:09,869 --> 00:02:13,090
what's the problem that we're trying to
solve the problem

37
00:02:13,090 --> 00:02:17,000
is the show called so for a crisis we
all know

38
00:02:17,000 --> 00:02:21,090
as developers that writing code is
pretty difficult

39
00:02:21,090 --> 00:02:24,180
riding huge programs and

40
00:02:24,180 --> 00:02:28,500
an what we need to do is to reduce the
time

41
00:02:28,500 --> 00:02:32,830
and the cost of development we on to
deliver software fast

42
00:02:32,830 --> 00:02:37,200
and we want to deliver correct offer the
question is

43
00:02:37,200 --> 00:02:40,440
how can we make programs

44
00:02:40,440 --> 00:02:44,260
search that we are confident that our
programs work

45
00:02:44,260 --> 00:02:47,609
and how can we make code

46
00:02:47,609 --> 00:02:50,959
such that this guard is delivered fast

47
00:02:50,959 --> 00:02:54,370
it doesn't take two years to deliver but
it takes you know

48
00:02:54,370 --> 00:03:00,970
months or as long as it needs to be one
way to do that and we see this now

49
00:03:00,970 --> 00:03:06,260
in all other programming languages is to
add features to our languages

50
00:03:06,260 --> 00:03:11,310
that allow programs to be written
clearly concisely and at a high level of

51
00:03:11,310 --> 00:03:12,220
abstraction

52
00:03:12,220 --> 00:03:16,319
and the techniques that we use in these
modern languages

53
00:03:16,319 --> 00:03:19,880
are all based on functional programming
these techniques

54
00:03:19,880 --> 00:03:23,989
are all based on concept from the lawn
the caucus

55
00:03:23,989 --> 00:03:27,410
and Haskell is a

56
00:03:27,410 --> 00:03:30,660
functional language that is pure and
therefore

57
00:03:30,660 --> 00:03:34,669
a really good vehicle to teach these
concept

58
00:03:34,669 --> 00:03:39,019
functional languages

59
00:03:39,019 --> 00:03:42,799
therefore provide very elegant framework

60
00:03:42,799 --> 00:03:46,120
to write code at a high level of
abstraction

61
00:03:46,120 --> 00:03:50,139
but as I said haskell is just our
vehicle

62
00:03:50,139 --> 00:03:55,329
so what we learned in this course you
will be able to apply dish

63
00:03:55,329 --> 00:03:59,169
to any language even if your programming
in assembly

64
00:03:59,169 --> 00:04:02,599
or in Java I or in PHP

65
00:04:02,599 --> 00:04:06,489
are in javascript all the ideas that you
will learn here

66
00:04:06,489 --> 00:04:09,720
you can apply immediately

67
00:04:09,720 --> 00:04:13,150
an in whatever language your happening
to use

68
00:04:13,150 --> 00:04:16,930
so what is a functional programming
language

69
00:04:16,930 --> 00:04:20,700
and the I ideas about that

70
00:04:20,700 --> 00:04:24,960
and very and there's no real clear
definition

71
00:04:24,960 --> 00:04:28,740
every take a very purist approach a
functional language

72
00:04:28,740 --> 00:04:32,800
is a language in which reprogram using
mathematical functions

73
00:04:32,800 --> 00:04:37,980
and that definition applies to Haskell
which is a pure language one of the very

74
00:04:37,980 --> 00:04:38,830
few

75
00:04:38,830 --> 00:04:42,320
functional programming languages that is
pure but of course

76
00:04:42,320 --> 00:04:46,860
and when I say that we can use these
techniques to program also in other

77
00:04:46,860 --> 00:04:47,670
languages

78
00:04:47,670 --> 00:04:52,020
an we cannot use that definition so

79
00:04:52,020 --> 00:04:56,020
what will use in discourse is the
following definition functional

80
00:04:56,020 --> 00:04:56,930
programming

81
00:04:56,930 --> 00:05:00,900
is a stockpile of programming m which

82
00:05:00,900 --> 00:05:04,310
expressions are more important than
using statement

83
00:05:04,310 --> 00:05:09,000
so what we want to do is you want to
compose programs using expressions

84
00:05:09,000 --> 00:05:13,800
and these expressions deliver a value so
we take two expressions that deliver

85
00:05:13,800 --> 00:05:14,530
value

86
00:05:14,530 --> 00:05:18,620
and composed and in a bigger expression
am

87
00:05:18,620 --> 00:05:23,780
compare and contrast that with writing
your program using statement

88
00:05:23,780 --> 00:05:28,040
when you compose statements the
statements have an implicit side-effect

89
00:05:28,040 --> 00:05:32,410
on the global stage and show they
communicate values fear that global

90
00:05:32,410 --> 00:05:32,880
state

91
00:05:32,880 --> 00:05:36,000
and whereas in an expression based

92
00:05:36,000 --> 00:05:40,620
an programming style expressions return
values

93
00:05:40,620 --> 00:05:46,320
and be composed these values directly
sore from Joe programming language

94
00:05:46,320 --> 00:05:50,190
is a language that supports and
encourages

95
00:05:50,190 --> 00:05:53,410
writing code using expressions

96
00:05:53,410 --> 00:05:57,230
and as I said before most modern
languages

97
00:05:57,230 --> 00:06:01,240
now support this style and they support
the style

98
00:06:01,240 --> 00:06:04,850
specifically by supporting lumber
expressions

99
00:06:04,850 --> 00:06:08,830
and we'll see examples of functional
programming

100
00:06:08,830 --> 00:06:11,960
in many many languages as we progress

101
00:06:11,960 --> 00:06:15,430
through discourse let's

102
00:06:15,430 --> 00:06:19,190
start with our first fragment of code
here an

103
00:06:19,190 --> 00:06:22,440
this is an some old-fashioned Java

104
00:06:22,440 --> 00:06:27,070
an where computing the song of the
integers from one to 10

105
00:06:27,070 --> 00:06:31,250
to the way we do that as i sat in the
traditional impaired

106
00:06:31,250 --> 00:06:33,820
style this is based by doing so

107
00:06:33,820 --> 00:06:38,530
statement showed the first thing we do
is we declare a variable total

108
00:06:38,530 --> 00:06:41,920
of type int we initialize did with zero

109
00:06:41,920 --> 00:06:46,380
and then rewrite the for loop with a
look fair ball

110
00:06:46,380 --> 00:06:49,660
that and I did you see there and then we

111
00:06:49,660 --> 00:06:53,530
a Cheyenne attitude that don't know
their bomb

112
00:06:53,530 --> 00:06:57,100
DoD all blush II to hear you she did

113
00:06:57,100 --> 00:07:00,240
the program is written

114
00:07:00,240 --> 00:07:03,860
imperative stop we have statements

115
00:07:03,860 --> 00:07:06,990
we have mutable state and we

116
00:07:06,990 --> 00:07:10,660
impaired if Lee execute statement after
statement

117
00:07:10,660 --> 00:07:14,160
updating the state to compute the result

118
00:07:14,160 --> 00:07:18,710
now here is how you would ride that same
program

119
00:07:18,710 --> 00:07:21,980
and Haskell the first thing you see is
that it's

120
00:07:21,980 --> 00:07:26,980
much more concise but the other thing is
that there's no statement is just

121
00:07:26,980 --> 00:07:30,230
at two expressions the expression you
see

122
00:07:30,230 --> 00:07:33,430
and here

123
00:07:33,430 --> 00:07:36,740
on the right one dot dot then

124
00:07:36,740 --> 00:07:40,300
create a list of the integers from one
to 10

125
00:07:40,300 --> 00:07:43,920
and then we just some those integers up

126
00:07:43,920 --> 00:07:47,380
so here you see that we're composing an

127
00:07:47,380 --> 00:07:52,670
the code by having an expression one
that creates this list from wanted an

128
00:07:52,670 --> 00:07:56,600
and then we apply that value

129
00:07:56,600 --> 00:07:59,680
to a function some that will somethings

130
00:07:59,680 --> 00:08:03,080
up for for now in Java 8

131
00:08:03,080 --> 00:08:06,670
you Camry ride the same code

132
00:08:06,670 --> 00:08:10,040
using Java it streams we will and

133
00:08:10,040 --> 00:08:14,070
dive deeper into Java 8 and a future

134
00:08:14,070 --> 00:08:17,590
lesson but for now here is the way

135
00:08:17,590 --> 00:08:21,990
we do this in Haskell thank you

136
00:08:21,990 --> 00:08:24,590
and CEO in part to do