Fast Development
Fast Development
Hack reconciles the fast development cycle of a dynamically typed language with the discipline provided by static typing, while adding many features commonly found in other modern programming languages.
Type Checking
Type Checking
Hack provides instantaneous type checking by incrementally checking your files as you edit them. It typically runs in less than 200 milliseconds, making it easy to integrate into your development workflow without introducing a noticeable delay.
Built for HHVM
Built for HHVM
Hack is built specifically for HHVM, a high performance runtime for your Hack applications.
Try it out!
There is a type mismatch on the right. Try and fix the error.
<?hh
class MyClass {
const int MyConst = 0;
private string $x = '';
public function increment(int $x): int {
$y = $x + 1;
return $y;
}
}
Type Annotations
Type annotations allow for code to be explicitly typed on parameters, class member variables and return values.
Generics
Generics allow classes and methods to be parameterized (i.e., a type associated when a class is instantiated or a method is called) in the same vein as statically type languages like C# and Java).
<?hh
class Box<T> {
protected T $data;
public function __construct(T $data) {
$this->data = $data;
}
public function getData(): T {
return $this->data;
}
}
<?hh
function foo(): (function(string): string) {
$x = 'bar';
return $y ==> $x . $y;
}
function test(): void {
$fn = foo();
echo $fn('baz'); // barbaz
}
Lambdas
Lambdas succinctly allow definition of first-class functions.