K
welcome everybody to another an jam session
in the a FB 1 along axed functional programming course
an and this a snippet
I'm going to show howdy I deres and
that we learnt in the main course and
it has girl can be applied and
in dotnet and in order to program dot net
I'll be using as ever in studio and
Semoran is in open source implementation of the dotnet framework
this cross-platform so if you want to ride codes
a in C sharp or Visual Basic
RXR only do sharp today but
and summer and supports the other two languages as well
and if you want a ride cross-platform don't that code that runs on the iPhone
Android
on Windows Phone on the Mac on Windows as ever in studio
is your tool of choice and because of that
and severance video is also my tool of choice
an but thats shutdown
open up number in studio and write some C sharp goat
an using functions and C sharp
as a couple of and dressing tourists
an that we haven't seen
and other languages so here is a.m. are severance DDR
and here is some sample
C sharp got and
as always an
sharp requires and then that
and it doesn't required to
YouTube of the arguments if you don't use them and here's the typical hello
world
console right line hello world and
I fear is our first example avail on the expressions or
the right inside here X double arrow ECs times do
in Long expression that multiplies the argument by two
and I and at sign it
do at here's another for my beloved expression that defines a function from
end to end H and and it takes
parameter axe and then
it uses a statement body and
with curly braces so does our to do form shoveling the expressions and here I
print af
and age now C sharp does support
an type inference so I can ride yeah
far and and Z
equals 42 and when I do this
an you see that
that its hasn't worked and forty do it the
editor here says you know this is redundant because I'm not using see
anywhere
but what I wanted to show you is that you can define
far here and the compiler
well in for that she had is has died and now you can
ask yourself why I can't be huge type inference here sure lets
an dried to
ride far here
and let's not forget the dive
and there is are far and that run this code and now what you see here said
it says implicitly typed local variable declaration
cannot be initialized with anonymous Matt
what does that all mean well the
thing here is that in c-sharp
I can use along the expression
and like we do below here just
go away good
am here I defined
another lund expression it's exactly the same on the expression
as here but instead of giving it to type
a funk from end to end I
say agent expression of funk
from and and this is it a super interesting
aspect of C sharp where a
love the expression by itself has no type
that's why I couldn't use type inference there but the ban
on the context where you sit on the expression
that long expression can't be turned into college
like here into a function or it can be
third into daytime like here and
into an expression and the price you pay
for that magic where you can take and
a long the expression and Bri presented
as an coat and
as daytime is the fact that you have to
gonna explicitly type damn
lech have a little appear G
and she
what intellisense tells us so what you see here now
is dead G has a body show that scan
get geez body and then an
here receive you have all kinda no matter its
on G so for example yeah can reduce et cetera
so this gives you a full API
to manipulate this long expression
as data and this mechanism is used very happily for example
in and Fri Mar like the Entity Framework
and and the old and Asian link to see call
where you can take fragments like this analyzed them
and compile them to see call and set I'm saying at
mike is a free search has also done some interesting work here for example where
he takes these
long the expressions and compiles them into FPGA
and people do all kinda interesting thanks an
and if you an our list programmer
the way you would do this is using quoting
and and this is gonna see sharks way of doing quoting
using as static types
and good and one thing that she sharp doesn't have
an and which we saw
and and other languages that didn't work for example ankle plan and
skyline in dart
is the idea local functions so you can have a
lund expression here and which is gonna be a local punch but I cannot define
an a function are matted just
like I defined here and inside another matter so
suppose I want to do define a cheer that nested inside
main and you see already here I get a syntax error
an that you cannot do this and our lives
I have already defined H let's define this gold this K
an but I still cannot do that am because
a and now it gives me a proper bar chair
saying that yeah you cannot have local
function declaration said i think thats and something that I do miss
and C sharp biggest now if you want to declare
matter like that yet to lift everything
to the top level
what else can we say about C sharp well and
comprehension so in c-sharp when I say here far
X's equals and neo
array and long comment to country for
5 so here we and haven't array
excess of values 135 you see this
full type inference I don't have to specify any types
and now i can say var wise equals
from X in X's where
X last and for
and select and X
times too okay and here you see
day and comprehension syntax in c-sharp
it looks a little bit like sequel and
and that on purpose showed these are called link comprehension
but they work exactly the same way as haskell list comprehension
talking about a an comprehension ce
sharper of course also supports the rage
of higher-order functions that the know and love
from Haskell so in this case if we look at
efforts type for wise that has type
I innumerable event and every use intellisense to show
and the message there that are available there we see
and that there are love Matt
in here and and sharp
goals them slightly different then am
ask all and other languages is Adam map
sharp and uses
select and and
bob up there is a little bit small but select is said
the version of mapping it takes a function and
binds are flat map a is called
like many if the look here there's a select many
and instead of filter and sharp
and uses where sup except for this little of our renaming
of these methods all the higher-order functions over collections and even more
and like group by and
jawans and are all available
and in the standard library alright
should if you want to get sharper or Visual Basic
RF sharp dry an
you can and immediately apply all day
thinks that you learned in the haskell part of the course
and to programming an in
these dotnet languages thank you and see you next time