1 00:00:00,849 --> 00:00:03,070 hey welcome everybody am 2 00:00:03,070 --> 00:00:06,350 in yet another jam session and 3 00:00:06,350 --> 00:00:10,210 for the functional programming 10 on X course 4 00:00:10,210 --> 00:00:14,160 and and this one we're going to 5 00:00:14,160 --> 00:00:17,170 and do a quick run 6 00:00:17,170 --> 00:00:21,750 over Facebook's and extensions to bhp 7 00:00:21,750 --> 00:00:25,840 gold heck and and hack 8 00:00:25,840 --> 00:00:30,300 really is and one way to look at it its PHP 9 00:00:30,300 --> 00:00:34,219 rate optional typing just like and art an 10 00:00:34,219 --> 00:00:37,760 and then there's some act quiet a interesting 11 00:00:37,760 --> 00:00:41,719 additional features that we have seen NC sharp 12 00:00:41,719 --> 00:00:44,829 and and and artist while search as 13 00:00:44,829 --> 00:00:48,450 a synchronous functions and iterators an 14 00:00:48,450 --> 00:00:51,469 and then the the and additions 15 00:00:51,469 --> 00:00:54,809 that heck brings to bhp are 16 00:00:54,809 --> 00:00:57,890 optional static typing and show you in 17 00:00:57,890 --> 00:01:01,120 and year you can kinda yeah specify the types 18 00:01:01,120 --> 00:01:04,949 and the other thing Islam the expressions and we will 19 00:01:04,949 --> 00:01:07,970 am walked through some examples there as well 20 00:01:07,970 --> 00:01:11,939 and examples will all be taken here from the heck 21 00:01:11,939 --> 00:01:15,210 website and and I 22 00:01:15,210 --> 00:01:19,159 invite you to gonna have a look at it and install hack 23 00:01:19,159 --> 00:01:23,320 am on your computer if you're a PHP programmer 24 00:01:23,320 --> 00:01:26,320 an I think this is definitely step 25 00:01:26,320 --> 00:01:29,890 up let's look at first 26 00:01:29,890 --> 00:01:34,240 at and the 27 00:01:34,240 --> 00:01:37,350 way 28 00:01:37,350 --> 00:01:42,299 you use and anonymous functions and BHP 29 00:01:42,299 --> 00:01:46,600 so in PHP and maybe I can make this 30 00:01:46,600 --> 00:01:49,860 a little bit larger to make it better readable 31 00:01:49,860 --> 00:01:54,759 so and BHP and like in C plus plus she bus bus 32 00:01:54,759 --> 00:02:00,590 am as long as as well and when you capture ferry boats from the outer scope 33 00:02:00,590 --> 00:02:04,750 you have to explicitly used them for example here 34 00:02:04,750 --> 00:02:08,190 we're there's a variable dollar ax here in 35 00:02:08,190 --> 00:02:11,790 and BHP and parables are 36 00:02:11,790 --> 00:02:16,670 and always have like this dollar sign in front so we have a fair ball dollar axe 37 00:02:16,670 --> 00:02:19,710 that initialized to bar and here's an 38 00:02:19,710 --> 00:02:24,360 anonymous function that we return this index is similar to Javascript or you 39 00:02:24,360 --> 00:02:25,680 have to write function 40 00:02:25,680 --> 00:02:29,450 parameter girly open body return so 41 00:02:29,450 --> 00:02:33,900 that's already rather for both but then hears that 42 00:02:33,900 --> 00:02:37,320 you always have to be to say which 43 00:02:37,320 --> 00:02:41,680 their balls from the Ardeche hope you're using an 44 00:02:41,680 --> 00:02:44,790 and so when you want to ride and 45 00:02:44,790 --> 00:02:48,540 goat in the higher-order style using 46 00:02:48,540 --> 00:02:52,850 filter and Matt an those kinda functions that we have seen 47 00:02:52,850 --> 00:02:56,610 and Haskell course the syntex here 48 00:02:56,610 --> 00:02:59,800 becomes very very heavyweight an 49 00:02:59,800 --> 00:03:03,420 and you know there's more noise 50 00:03:03,420 --> 00:03:08,170 an then really what you gain 100 51 00:03:08,170 --> 00:03:11,220 very nice things in hac is that hack 52 00:03:11,220 --> 00:03:14,540 support love the expressions which makes 53 00:03:14,540 --> 00:03:18,100 the user anonymous functions and BHP 54 00:03:18,100 --> 00:03:21,710 much much more concise so and that's ok at 55 00:03:21,710 --> 00:03:25,460 and the example here 56 00:03:25,460 --> 00:03:28,830 so an every ever 57 00:03:28,830 --> 00:03:32,930 a function that a captures be 58 00:03:32,930 --> 00:03:36,010 from the outer scope so that's used be here 59 00:03:36,010 --> 00:03:39,280 but we don't have to say any use here 60 00:03:39,280 --> 00:03:42,360 and also this syntax is much more concise 61 00:03:42,360 --> 00:03:46,440 weekend just say dollar a that's the brand matter 62 00:03:46,440 --> 00:03:50,470 arrow and then triple arrow and the website 63 00:03:50,470 --> 00:03:55,040 here baggage in very interesting explanation of why 64 00:03:55,040 --> 00:03:58,300 thats index was used not single arrow or not yeah 65 00:03:58,300 --> 00:04:03,600 single double arrow and but here you see that we don't have to ride 66 00:04:03,600 --> 00:04:07,300 am old this an 67 00:04:07,300 --> 00:04:11,370 noise we don't have the right functions we don't have to ride 68 00:04:11,370 --> 00:04:16,040 use and now suddenly writing higher-order functions like Matt 69 00:04:16,040 --> 00:04:19,040 filter fault becomes and rather 70 00:04:19,040 --> 00:04:22,020 easy and so I thats that 71 00:04:22,020 --> 00:04:25,320 a quiet and nice thing good 72 00:04:25,320 --> 00:04:30,220 let's look at some other features of of fact that we have seen in Haskell 73 00:04:30,220 --> 00:04:34,000 anti Bailey SS we have seen type aliases also 74 00:04:34,000 --> 00:04:37,400 in Scala and Haskell if you want to give a name 75 00:04:37,400 --> 00:04:41,750 a different name do some type you just defined 76 00:04:41,750 --> 00:04:45,090 type alias and and hack 77 00:04:45,090 --> 00:04:48,120 you can do that here and there are 78 00:04:48,120 --> 00:04:52,650 a.m. also new type that's the same concept 79 00:04:52,650 --> 00:04:55,990 as in has car and so on so I show 80 00:04:55,990 --> 00:04:59,680 hack has a number of ways to define 81 00:04:59,680 --> 00:05:03,980 died aliases and there you see here dares 82 00:05:03,980 --> 00:05:07,620 and ok I'm all as mentioned an 83 00:05:07,620 --> 00:05:13,210 interestingly heck compiler itself is written in OCaml 84 00:05:13,210 --> 00:05:16,440 an that's an example Ave 85 00:05:16,440 --> 00:05:20,190 very large piece of software written in the functional language 86 00:05:20,190 --> 00:05:24,950 that is used at and you know a major Internet company 87 00:05:24,950 --> 00:05:28,180 and and also many of the and 88 00:05:28,180 --> 00:05:31,320 ideas in hack have been 89 00:05:31,320 --> 00:05:35,270 entranced by and the O'Connell language 90 00:05:35,270 --> 00:05:38,420 so there you see another example where a functional language 91 00:05:38,420 --> 00:05:42,190 ok I'm all is boat used in the implementation 92 00:05:42,190 --> 00:05:45,370 of and dish %eh the an 93 00:05:45,370 --> 00:05:48,620 there every day but also did design 94 00:05:48,620 --> 00:05:51,660 of hack has been entranced by 95 00:05:51,660 --> 00:05:56,120 functional language Biochem and at 96 00:05:56,120 --> 00:05:59,130 very nice that's 97 00:05:59,130 --> 00:06:02,230 we've seen lund expressions here are 98 00:06:02,230 --> 00:06:08,140 an generators and in c-sharp their shield return 99 00:06:08,140 --> 00:06:14,340 we've seen does in am dart as well with the sink star Matt it's 100 00:06:14,340 --> 00:06:18,610 JavaScript ECMAScript 6 and will also support 101 00:06:18,610 --> 00:06:21,870 yields and BHP 102 00:06:21,870 --> 00:06:25,370 already an support 103 00:06:25,370 --> 00:06:28,480 support generators here so you can 104 00:06:28,480 --> 00:06:32,110 and ride inside the function body you can 105 00:06:32,110 --> 00:06:35,319 used yield and then the result %uh this 106 00:06:35,319 --> 00:06:38,720 and will be an an iterable 107 00:06:38,720 --> 00:06:42,220 and the nice thing about this is that if you use these 108 00:06:42,220 --> 00:06:47,050 an iterators and I i haven't shown them in C sharp in c-sharp 109 00:06:47,050 --> 00:06:50,229 I've shown an only the link comprehension 110 00:06:50,229 --> 00:06:53,630 but with iterators its kind of the impaired if 111 00:06:53,630 --> 00:06:57,919 equivalent of comprehension because sometimes 112 00:06:57,919 --> 00:07:01,479 you want to generate an a collection 113 00:07:01,479 --> 00:07:06,500 but you want to maintain some states and the you want to use regular control flow 114 00:07:06,500 --> 00:07:09,690 like dry catch em for loops and 115 00:07:09,690 --> 00:07:12,740 while loops and and in that case the 116 00:07:12,740 --> 00:07:16,380 an iterators 117 00:07:16,380 --> 00:07:20,310 or generators as there sometime called are super convenient because 118 00:07:20,310 --> 00:07:25,060 it just allows you to write the same kind of cotija right in normal 119 00:07:25,060 --> 00:07:28,470 function bodies but now you can 120 00:07:28,470 --> 00:07:32,259 temporarily suspend to function body when you want to yield 121 00:07:32,259 --> 00:07:35,370 value and then when the consumer goals move next 122 00:07:35,370 --> 00:07:40,220 execution continues here the other thing that 123 00:07:40,220 --> 00:07:43,560 in and hack and that ish 124 00:07:43,560 --> 00:07:46,729 quite nice and that's also in c-sharp 125 00:07:46,729 --> 00:07:49,820 and as we've seen also in dart are 126 00:07:49,820 --> 00:07:53,219 an a synchronous functions so and 127 00:07:53,219 --> 00:07:56,610 if you define a function you say that it's 128 00:07:56,610 --> 00:08:00,330 a synchronous an then inside that function 129 00:08:00,330 --> 00:08:04,740 you can call await on another a synchronous function 130 00:08:04,740 --> 00:08:08,030 and this a single instructions returns and 131 00:08:08,030 --> 00:08:11,150 a way to bowl of an some value 132 00:08:11,150 --> 00:08:14,389 and the way to ball say roughly is 133 00:08:14,389 --> 00:08:19,479 what corresponds to a task in c-sharp our future and job I 134 00:08:19,479 --> 00:08:23,570 or future and art an and 135 00:08:23,570 --> 00:08:27,320 so this awaits takes on the right hand side 136 00:08:27,320 --> 00:08:30,849 a an await a ball of tea and then 137 00:08:30,849 --> 00:08:34,190 turns that into and eighty and 138 00:08:34,190 --> 00:08:37,490 under the covers at the compiler will create 139 00:08:37,490 --> 00:08:41,510 a state machine that well and take the continuation 140 00:08:41,510 --> 00:08:43,520 up this program here so there 141 00:08:43,520 --> 00:08:46,750 rest of the computation it's basically am 142 00:08:46,750 --> 00:08:50,330 what's highlighted here and boss that as the gold back 143 00:08:50,330 --> 00:08:53,540 and when that way to ball has terminated 144 00:08:53,540 --> 00:08:57,990 and I think that's a 145 00:08:57,990 --> 00:09:03,110 that's about it for an for for hack so if you go to the heck website 146 00:09:03,110 --> 00:09:07,800 it well it has I am fantastic documentation 147 00:09:07,800 --> 00:09:11,390 there's a lot of some balls tutorials 148 00:09:11,390 --> 00:09:15,380 an and and there's also 149 00:09:15,380 --> 00:09:19,440 I am instructions how to install it on your own computer 150 00:09:19,440 --> 00:09:22,660 if your are a PHP programmer and 151 00:09:22,660 --> 00:09:26,010 and you're interested in using a much more 152 00:09:26,010 --> 00:09:30,130 functional programming style I would deftly 153 00:09:30,130 --> 00:09:33,910 and in our advice you 154 00:09:33,910 --> 00:09:37,430 to give hackett try an and as I mentioned 155 00:09:37,430 --> 00:09:41,800 and heck compiler is written in OCaml 156 00:09:41,800 --> 00:09:46,540 an and so the influences functional programming here 157 00:09:46,540 --> 00:09:50,050 are very apparent and which is always 158 00:09:50,050 --> 00:09:53,080 beautiful thank you very much and 159 00:09:53,080 --> 00:09:53,870 happy hacking