1 00:00:02,860 --> 00:00:03,350 K 2 00:00:03,350 --> 00:00:07,629 welcome everybody to another an jam session 3 00:00:07,629 --> 00:00:11,660 in the a FB 1 along axed functional programming course 4 00:00:11,660 --> 00:00:14,730 an and this a snippet 5 00:00:14,730 --> 00:00:18,520 I'm going to show howdy I deres and 6 00:00:18,520 --> 00:00:22,289 that we learnt in the main course and 7 00:00:22,289 --> 00:00:25,550 it has girl can be applied and 8 00:00:25,550 --> 00:00:29,380 in dotnet and in order to program dot net 9 00:00:29,380 --> 00:00:32,850 I'll be using as ever in studio and 10 00:00:32,850 --> 00:00:37,090 Semoran is in open source implementation of the dotnet framework 11 00:00:37,090 --> 00:00:40,530 this cross-platform so if you want to ride codes 12 00:00:40,530 --> 00:00:43,570 a in C sharp or Visual Basic 13 00:00:43,570 --> 00:00:47,559 RXR only do sharp today but 14 00:00:47,559 --> 00:00:52,670 and summer and supports the other two languages as well 15 00:00:52,670 --> 00:00:57,600 and if you want a ride cross-platform don't that code that runs on the iPhone 16 00:00:57,600 --> 00:00:58,629 Android 17 00:00:58,629 --> 00:01:03,510 on Windows Phone on the Mac on Windows as ever in studio 18 00:01:03,510 --> 00:01:06,909 is your tool of choice and because of that 19 00:01:06,909 --> 00:01:11,159 and severance video is also my tool of choice 20 00:01:11,159 --> 00:01:15,470 an but thats shutdown 21 00:01:15,470 --> 00:01:19,490 open up number in studio and write some C sharp goat 22 00:01:19,490 --> 00:01:22,960 an using functions and C sharp 23 00:01:22,960 --> 00:01:26,479 as a couple of and dressing tourists 24 00:01:26,479 --> 00:01:29,650 an that we haven't seen 25 00:01:29,650 --> 00:01:34,180 and other languages so here is a.m. are severance DDR 26 00:01:34,180 --> 00:01:37,740 and here is some sample 27 00:01:37,740 --> 00:01:41,799 C sharp got and 28 00:01:41,799 --> 00:01:44,960 as always an 29 00:01:44,960 --> 00:01:48,360 sharp requires and then that 30 00:01:48,360 --> 00:01:51,610 and it doesn't required to 31 00:01:51,610 --> 00:01:56,299 YouTube of the arguments if you don't use them and here's the typical hello 32 00:01:56,299 --> 00:01:56,860 world 33 00:01:56,860 --> 00:02:02,600 console right line hello world and 34 00:02:02,600 --> 00:02:05,799 I fear is our first example avail on the expressions or 35 00:02:05,799 --> 00:02:09,899 the right inside here X double arrow ECs times do 36 00:02:09,899 --> 00:02:14,770 in Long expression that multiplies the argument by two 37 00:02:14,770 --> 00:02:18,129 and I and at sign it 38 00:02:18,129 --> 00:02:23,090 do at here's another for my beloved expression that defines a function from 39 00:02:23,090 --> 00:02:26,150 end to end H and and it takes 40 00:02:26,150 --> 00:02:29,209 parameter axe and then 41 00:02:29,209 --> 00:02:32,940 it uses a statement body and 42 00:02:32,940 --> 00:02:38,650 with curly braces so does our to do form shoveling the expressions and here I 43 00:02:38,650 --> 00:02:39,540 print af 44 00:02:39,540 --> 00:02:43,730 and age now C sharp does support 45 00:02:43,730 --> 00:02:46,739 an type inference so I can ride yeah 46 00:02:46,739 --> 00:02:50,910 far and and Z 47 00:02:50,910 --> 00:02:55,000 equals 42 and when I do this 48 00:02:55,000 --> 00:03:02,000 an you see that 49 00:03:02,140 --> 00:03:08,450 that its hasn't worked and forty do it the 50 00:03:08,450 --> 00:03:12,580 editor here says you know this is redundant because I'm not using see 51 00:03:12,580 --> 00:03:13,390 anywhere 52 00:03:13,390 --> 00:03:17,409 but what I wanted to show you is that you can define 53 00:03:17,409 --> 00:03:20,700 far here and the compiler 54 00:03:20,700 --> 00:03:26,769 well in for that she had is has died and now you can 55 00:03:26,769 --> 00:03:31,709 ask yourself why I can't be huge type inference here sure lets 56 00:03:31,709 --> 00:03:34,890 an dried to 57 00:03:34,890 --> 00:03:37,930 ride far here 58 00:03:37,930 --> 00:03:41,709 and let's not forget the dive 59 00:03:41,709 --> 00:03:47,860 and there is are far and that run this code and now what you see here said 60 00:03:47,860 --> 00:03:51,930 it says implicitly typed local variable declaration 61 00:03:51,930 --> 00:03:55,099 cannot be initialized with anonymous Matt 62 00:03:55,099 --> 00:04:00,099 what does that all mean well the 63 00:04:00,099 --> 00:04:03,819 thing here is that in c-sharp 64 00:04:03,819 --> 00:04:06,879 I can use along the expression 65 00:04:06,879 --> 00:04:10,599 and like we do below here just 66 00:04:10,599 --> 00:04:14,739 go away good 67 00:04:14,739 --> 00:04:18,680 am here I defined 68 00:04:18,680 --> 00:04:22,100 another lund expression it's exactly the same on the expression 69 00:04:22,100 --> 00:04:25,910 as here but instead of giving it to type 70 00:04:25,910 --> 00:04:29,070 a funk from end to end I 71 00:04:29,070 --> 00:04:32,100 say agent expression of funk 72 00:04:32,100 --> 00:04:36,639 from and and this is it a super interesting 73 00:04:36,639 --> 00:04:39,949 aspect of C sharp where a 74 00:04:39,949 --> 00:04:43,680 love the expression by itself has no type 75 00:04:43,680 --> 00:04:47,660 that's why I couldn't use type inference there but the ban 76 00:04:47,660 --> 00:04:50,949 on the context where you sit on the expression 77 00:04:50,949 --> 00:04:54,400 that long expression can't be turned into college 78 00:04:54,400 --> 00:04:57,830 like here into a function or it can be 79 00:04:57,830 --> 00:05:00,990 third into daytime like here and 80 00:05:00,990 --> 00:05:05,130 into an expression and the price you pay 81 00:05:05,130 --> 00:05:08,310 for that magic where you can take and 82 00:05:08,310 --> 00:05:11,919 a long the expression and Bri presented 83 00:05:11,919 --> 00:05:14,960 as an coat and 84 00:05:14,960 --> 00:05:18,220 as daytime is the fact that you have to 85 00:05:18,220 --> 00:05:22,220 gonna explicitly type damn 86 00:05:22,220 --> 00:05:25,770 lech have a little appear G 87 00:05:25,770 --> 00:05:29,289 and she 88 00:05:29,289 --> 00:05:33,120 what intellisense tells us so what you see here now 89 00:05:33,120 --> 00:05:36,190 is dead G has a body show that scan 90 00:05:36,190 --> 00:05:39,800 get geez body and then an 91 00:05:39,800 --> 00:05:43,039 here receive you have all kinda no matter its 92 00:05:43,039 --> 00:05:46,740 on G so for example yeah can reduce et cetera 93 00:05:46,740 --> 00:05:50,470 so this gives you a full API 94 00:05:50,470 --> 00:05:54,160 to manipulate this long expression 95 00:05:54,160 --> 00:05:59,220 as data and this mechanism is used very happily for example 96 00:05:59,220 --> 00:06:04,419 in and Fri Mar like the Entity Framework 97 00:06:04,419 --> 00:06:07,500 and and the old and Asian link to see call 98 00:06:07,500 --> 00:06:11,650 where you can take fragments like this analyzed them 99 00:06:11,650 --> 00:06:15,490 and compile them to see call and set I'm saying at 100 00:06:15,490 --> 00:06:19,569 mike is a free search has also done some interesting work here for example where 101 00:06:19,569 --> 00:06:20,520 he takes these 102 00:06:20,520 --> 00:06:24,669 long the expressions and compiles them into FPGA 103 00:06:24,669 --> 00:06:28,120 and people do all kinda interesting thanks an 104 00:06:28,120 --> 00:06:31,850 and if you an our list programmer 105 00:06:31,850 --> 00:06:35,020 the way you would do this is using quoting 106 00:06:35,020 --> 00:06:38,639 and and this is gonna see sharks way of doing quoting 107 00:06:38,639 --> 00:06:42,199 using as static types 108 00:06:42,199 --> 00:06:47,199 and good and one thing that she sharp doesn't have 109 00:06:47,199 --> 00:06:50,419 an and which we saw 110 00:06:50,419 --> 00:06:55,729 and and other languages that didn't work for example ankle plan and 111 00:06:55,729 --> 00:06:58,970 skyline in dart 112 00:06:58,970 --> 00:07:02,990 is the idea local functions so you can have a 113 00:07:02,990 --> 00:07:08,190 lund expression here and which is gonna be a local punch but I cannot define 114 00:07:08,190 --> 00:07:11,270 an a function are matted just 115 00:07:11,270 --> 00:07:15,419 like I defined here and inside another matter so 116 00:07:15,419 --> 00:07:19,240 suppose I want to do define a cheer that nested inside 117 00:07:19,240 --> 00:07:23,090 main and you see already here I get a syntax error 118 00:07:23,090 --> 00:07:26,530 an that you cannot do this and our lives 119 00:07:26,530 --> 00:07:30,680 I have already defined H let's define this gold this K 120 00:07:30,680 --> 00:07:33,840 an but I still cannot do that am because 121 00:07:33,840 --> 00:07:37,849 a and now it gives me a proper bar chair 122 00:07:37,849 --> 00:07:40,889 saying that yeah you cannot have local 123 00:07:40,889 --> 00:07:45,509 function declaration said i think thats and something that I do miss 124 00:07:45,509 --> 00:07:49,330 and C sharp biggest now if you want to declare 125 00:07:49,330 --> 00:07:52,900 matter like that yet to lift everything 126 00:07:52,900 --> 00:07:55,990 to the top level 127 00:07:55,990 --> 00:07:59,090 what else can we say about C sharp well and 128 00:07:59,090 --> 00:08:03,129 comprehension so in c-sharp when I say here far 129 00:08:03,129 --> 00:08:06,240 X's equals and neo 130 00:08:06,240 --> 00:08:09,639 array and long comment to country for 131 00:08:09,639 --> 00:08:13,759 5 so here we and haven't array 132 00:08:13,759 --> 00:08:16,800 excess of values 135 you see this 133 00:08:16,800 --> 00:08:19,949 full type inference I don't have to specify any types 134 00:08:19,949 --> 00:08:23,750 and now i can say var wise equals 135 00:08:23,750 --> 00:08:27,410 from X in X's where 136 00:08:27,410 --> 00:08:30,569 X last and for 137 00:08:30,569 --> 00:08:34,099 and select and X 138 00:08:34,099 --> 00:08:38,349 times too okay and here you see 139 00:08:38,349 --> 00:08:42,250 day and comprehension syntax in c-sharp 140 00:08:42,250 --> 00:08:46,339 it looks a little bit like sequel and 141 00:08:46,339 --> 00:08:50,519 and that on purpose showed these are called link comprehension 142 00:08:50,519 --> 00:08:54,930 but they work exactly the same way as haskell list comprehension 143 00:08:54,930 --> 00:08:59,260 talking about a an comprehension ce 144 00:08:59,260 --> 00:09:02,720 sharper of course also supports the rage 145 00:09:02,720 --> 00:09:05,959 of higher-order functions that the know and love 146 00:09:05,959 --> 00:09:09,130 from Haskell so in this case if we look at 147 00:09:09,130 --> 00:09:13,080 efforts type for wise that has type 148 00:09:13,080 --> 00:09:17,790 I innumerable event and every use intellisense to show 149 00:09:17,790 --> 00:09:21,950 and the message there that are available there we see 150 00:09:21,950 --> 00:09:25,029 and that there are love Matt 151 00:09:25,029 --> 00:09:28,589 in here and and sharp 152 00:09:28,589 --> 00:09:32,839 goals them slightly different then am 153 00:09:32,839 --> 00:09:36,350 ask all and other languages is Adam map 154 00:09:36,350 --> 00:09:39,390 sharp and uses 155 00:09:39,390 --> 00:09:44,230 select and and 156 00:09:44,230 --> 00:09:47,760 bob up there is a little bit small but select is said 157 00:09:47,760 --> 00:09:51,830 the version of mapping it takes a function and 158 00:09:51,830 --> 00:09:55,209 binds are flat map a is called 159 00:09:55,209 --> 00:09:59,410 like many if the look here there's a select many 160 00:09:59,410 --> 00:10:03,140 and instead of filter and sharp 161 00:10:03,140 --> 00:10:08,519 and uses where sup except for this little of our renaming 162 00:10:08,519 --> 00:10:14,930 of these methods all the higher-order functions over collections and even more 163 00:10:14,930 --> 00:10:18,820 and like group by and 164 00:10:18,820 --> 00:10:21,860 jawans and are all available 165 00:10:21,860 --> 00:10:25,160 and in the standard library alright 166 00:10:25,160 --> 00:10:29,089 should if you want to get sharper or Visual Basic 167 00:10:29,089 --> 00:10:32,440 RF sharp dry an 168 00:10:32,440 --> 00:10:36,450 you can and immediately apply all day 169 00:10:36,450 --> 00:10:40,500 thinks that you learned in the haskell part of the course 170 00:10:40,500 --> 00:10:43,839 and to programming an in 171 00:10:43,839 --> 00:10:46,690 these dotnet languages thank you and see you next time