Questions tagged [hacklang]

Hack is a open source programming language that reconciles the fast development cycle of PHP with the discipline provided by static typing, while adding many features commonly found in other modern programming languages.

What is Hack?

Find complete documentation at http://www.hacklang.org/

Hack is a open source programming language for HHVM that interoperates seamlessly with PHP, it was invented by Facebook. Hack reconciles the fast development cycle of PHP with the discipline provided by static typing, while adding many features commonly found in other modern programming languages.

Hack provides instantaneous type checking via a local server that watches the filesystem. It typically runs in less than 200 milliseconds, making it easy to integrate into your development workflow without introducing a noticeable delay.

The following are some of the important language features of Hack. For more information, see the full documentation, or follow through the quick interactive tutorial.

  • Type Annotations allow for PHP code to be explicitly typed on parameters, class member variables and return values:

    <?hh
    class MyClass {
      const int MyConst = 0;
      private string $x = '';
      public function increment(int $x): int {
        $y = $x + 1;
        return $y;
      }
    }
    
  • 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;
      }
    }
    
  • Nullable Types are supported by Hack through use of the ? operator. This introduces a safer way to deal with nulls and is very useful for primitive types that don’t generally allow null as one of their values, such as bool and int (using ?bool and ?int respectively). The operand be used on any type or class.

  • Collections enhance the experience of working with PHP arrays, by providing first class, built-in parameterized types such as Vector (an ordered, index-based list), Map (an ordered dictionary), Set (a list of unique values), and Pair (an index-based collection of exactly two elements).

  • Lambdas offer similar functionality to PHP closures, but they capture variables from the enclosing function body implicitly and are less verbose:

    <?hh
    function foo(): (function(string): string) {
      $x = 'bar';
      return $y ==> $x . $y;
    }
    function test(): void {
      $fn = foo();
      echo $fn('baz'); // barbaz
    }
    

Other significant features of Hack include Shapes, Type Aliasing, Async support, and much more.

176 questions
0
votes
1 answer

Can't find OCaml module FileInfo when compiling parts of Hack

I'm trying to compile parts of the Hack compiler, specifically the parser/lexer/ast part, but the module FileInfo is missing. Is it made in C? How would I include it?
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
0
votes
1 answer

Function or method as value in collection

Is it possible to pass a function or method call as value in a collection of any type? $collection = Vector { function(){} }; The code above throws Fatal error: syntax error, unexpected T_FUNCTION, expecting '}'
musse1
  • 379
  • 4
  • 17
0
votes
2 answers

Hacklang async code example?

How modify the following code to get article data and top articles asynchronously in hack ? class ArticleController { public function viewAction() { // how get $article = $this->getArticleData(); $topArticles =…
Marty Aghajanyan
  • 12,651
  • 8
  • 35
  • 37
0
votes
1 answer

Hack back to php

I was looking at the hack language of Facebook but I have a server running several php sites. Now I was wondering if there is a tool that can convert hack back to php, so it can be run it on my server but I can develop in hack?
Spidfire
  • 5,433
  • 6
  • 28
  • 36
0
votes
1 answer

What's the status regarding HHVM?

I just discovered HHVM, a virtual machine designed to execute PHP (and a closely-related new language called Hack) much more efficiently than the standard PHP interpreter. Read about it at hhvm.com. (I think this started with an effort by Facebook…
user3238181
  • 115
  • 1
  • 10
-1
votes
1 answer

Collection elements cannot be taken by reference in php

I have multidimensional map (collection) $data in PHP hack. I want to search for a key 'road' and replace its value with map{ 'test' => abc}; I have key arrays as $keys = ['meta', 'attr', 'road']; below is my Map $data = Map {'meta' => Map…
Vish021
  • 399
  • 1
  • 5
  • 18
-2
votes
4 answers

What is the file extension for the Hack programming language?

Does anyone know the file extension for Hack? I've looked pretty much everywhere, and can't seem to find it. Thanks
William Lee
  • 93
  • 1
  • 10
-2
votes
1 answer

Can someone tell about this new HACK programming language from facebook

I cant find many resources about it on the internet. I would like too look into this more and what similarities does it have with javascript!
-3
votes
1 answer

How to convert Unicode codepoint to UTF-8 Hex Bytes?

Given a list of all emojis, I need to convert unicode codepoint to UTF-8 hex bytes programmatically. For example: Take this emoji: https://unicode-table.com/en/1F606/ and convert 1F606 to F0 9F 98 86 Please provide code examples in python or…
-3
votes
1 answer

How is the Hack language's type system defined?

Please give a precise description of the Hack language's type system. It doesn't seem to exist online -- all I can find are examples sprinkled throughout the docs -- so please describe it in great detail in your answer. For example, I would like…
ntc2
  • 11,203
  • 7
  • 53
  • 70
-5
votes
1 answer

When FBIDE will be released?

FB guys on some talk you said, that it will be in summer 14', but now already spring 15'. Do you have any plans? Currently one big blocker to move to Hack language is missing plugins for popular free IDEs like eclipse/netbeans/other (atom with it's…
gaRex
  • 4,144
  • 25
  • 37
1 2 3
11
12