facebook launched a new programming language for HHVM

Hack is a programming language for the HipHop Virtual Machine (HHVM) invented by Facebook.Hack can be seen as a new version of PHP that also runs on the HHVM, but it allows programmers to use both dynamic typing and static typing.

This is what is called gradual typing, which has been mostly seen as an academic exercise; as described by Facebook, it is the first to bring gradual typing to a “real, industrial strength” language.


Hack Features

Hack interoperates seamlessly with PHP, which is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. Majority of scripts that are valid in PHP are also valid in Hack.[4] Hack’s type system allows types to be specified for function arguments, function return values, and class properties; types of local variables cannot be specified.

Syntax and Example

The basic file structure of a Hack script is similar to a PHP script with a few changes. A Hack file starts with < ?hh as opposed to &lt;?hh
function increment(int $x): int {
return $x + 1;

function average(float $x, float $y): float {
return ($x + $y) / 2;

function say_hello(string $name): string {
return “Hello “.$name;

function invert(bool $b): bool {
if ($b) {
return false;
} else {
return true;

function sort(array $arr): array {
return $arr;

// A piece of code that computes the average of three numbers
function avg(int $n1, int $n2, int $n3): float {
$s = $n1 + $n2 + $n3;
return $s / 3.0;



There are many people who have contributed to the development of Hack.

The core Hack team consists of Julien Verlaguet, Joel Beales, Eugene Letuchy, Gabriel Levi, Joel Marcey, Erik Meijer, Alok Menghrajani, Bryan O’Sullivan, Drew Paroski, James Pearce, Joel Pobar, and Joshua Van Dyke Watzman.

A special thanks goes to our early community adopters for providing valuable feedback to make the language better: James Miller, Simon Welsh, Nils Adermann, Fabien Potencier, and Alexander Mols.

Hack is written primarily in OCaml. We would like to thank the Gallium team (INRIA) for the development of the OCaml language, and the Ocsigen team (CNRS – University of Paris Diderot – INRIA) for the development of the js_of_ocaml part of Ocsigen.

And, of course, thank you to everyone else who has helped make Hack the language it is today. The list is too exhaustive for a blog post, but you know who you are.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: , , , , ,