hey welcome everybody am
in yet another jam session and
for the functional programming 10 on X course
and and this one we're going to
and do a quick run
over Facebook's and extensions to bhp
gold heck and and hack
really is and one way to look at it its PHP
rate optional typing just like and art an
and then there's some act quiet a interesting
additional features that we have seen NC sharp
and and and artist while search as
a synchronous functions and iterators an
and then the the and additions
that heck brings to bhp are
optional static typing and show you in
and year you can kinda yeah specify the types
and the other thing Islam the expressions and we will
am walked through some examples there as well
and examples will all be taken here from the heck
website and and I
invite you to gonna have a look at it and install hack
am on your computer if you're a PHP programmer
an I think this is definitely step
up let's look at first
at and the
way
you use and anonymous functions and BHP
so in PHP and maybe I can make this
a little bit larger to make it better readable
so and BHP and like in C plus plus she bus bus
am as long as as well and when you capture ferry boats from the outer scope
you have to explicitly used them for example here
we're there's a variable dollar ax here in
and BHP and parables are
and always have like this dollar sign in front so we have a fair ball dollar axe
that initialized to bar and here's an
anonymous function that we return this index is similar to Javascript or you
have to write function
parameter girly open body return so
that's already rather for both but then hears that
you always have to be to say which
their balls from the Ardeche hope you're using an
and so when you want to ride and
goat in the higher-order style using
filter and Matt an those kinda functions that we have seen
and Haskell course the syntex here
becomes very very heavyweight an
and you know there's more noise
an then really what you gain 100
very nice things in hac is that hack
support love the expressions which makes
the user anonymous functions and BHP
much much more concise so and that's ok at
and the example here
so an every ever
a function that a captures be
from the outer scope so that's used be here
but we don't have to say any use here
and also this syntax is much more concise
weekend just say dollar a that's the brand matter
arrow and then triple arrow and the website
here baggage in very interesting explanation of why
thats index was used not single arrow or not yeah
single double arrow and but here you see that we don't have to ride
am old this an
noise we don't have the right functions we don't have to ride
use and now suddenly writing higher-order functions like Matt
filter fault becomes and rather
easy and so I thats that
a quiet and nice thing good
let's look at some other features of of fact that we have seen in Haskell
anti Bailey SS we have seen type aliases also
in Scala and Haskell if you want to give a name
a different name do some type you just defined
type alias and and hack
you can do that here and there are
a.m. also new type that's the same concept
as in has car and so on so I show
hack has a number of ways to define
died aliases and there you see here dares
and ok I'm all as mentioned an
interestingly heck compiler itself is written in OCaml
an that's an example Ave
very large piece of software written in the functional language
that is used at and you know a major Internet company
and and also many of the and
ideas in hack have been
entranced by and the O'Connell language
so there you see another example where a functional language
ok I'm all is boat used in the implementation
of and dish %eh the an
there every day but also did design
of hack has been entranced by
functional language Biochem and at
very nice that's
we've seen lund expressions here are
an generators and in c-sharp their shield return
we've seen does in am dart as well with the sink star Matt it's
JavaScript ECMAScript 6 and will also support
yields and BHP
already an support
support generators here so you can
and ride inside the function body you can
used yield and then the result %uh this
and will be an an iterable
and the nice thing about this is that if you use these
an iterators and I i haven't shown them in C sharp in c-sharp
I've shown an only the link comprehension
but with iterators its kind of the impaired if
equivalent of comprehension because sometimes
you want to generate an a collection
but you want to maintain some states and the you want to use regular control flow
like dry catch em for loops and
while loops and and in that case the
an iterators
or generators as there sometime called are super convenient because
it just allows you to write the same kind of cotija right in normal
function bodies but now you can
temporarily suspend to function body when you want to yield
value and then when the consumer goals move next
execution continues here the other thing that
in and hack and that ish
quite nice and that's also in c-sharp
and as we've seen also in dart are
an a synchronous functions so and
if you define a function you say that it's
a synchronous an then inside that function
you can call await on another a synchronous function
and this a single instructions returns and
a way to bowl of an some value
and the way to ball say roughly is
what corresponds to a task in c-sharp our future and job I
or future and art an and
so this awaits takes on the right hand side
a an await a ball of tea and then
turns that into and eighty and
under the covers at the compiler will create
a state machine that well and take the continuation
up this program here so there
rest of the computation it's basically am
what's highlighted here and boss that as the gold back
and when that way to ball has terminated
and I think that's a
that's about it for an for for hack so if you go to the heck website
it well it has I am fantastic documentation
there's a lot of some balls tutorials
an and and there's also
I am instructions how to install it on your own computer
if your are a PHP programmer and
and you're interested in using a much more
functional programming style I would deftly
and in our advice you
to give hackett try an and as I mentioned
and heck compiler is written in OCaml
an and so the influences functional programming here
are very apparent and which is always
beautiful thank you very much and
happy hacking