标签: hacklang

hacklang中的线性类型:静态强制函数调用的顺序

因此,Hacklang推出了一个新的,花哨的类型系统,在可以使用之前必须检查可以为空的变量.我想知道的是,你能实现类似线性类型的东西,静态强制函数调用的顺序,常见的例子是在读取之前打开文件吗?在伪代码中:

$file_handler = get_file_handler("myfile");
$file_handler->open();
$string = $file_handler->read();
Run Code Online (Sandbox Code Playgroud)

现在,$file_handler->read()不用open()抛出运行时异常,而不是编译:

$file_handler = get_file_handler("myfile");
$string = $file_handler->read(); /* Won't compile, must run open() first */
Run Code Online (Sandbox Code Playgroud)

可行?

(好吧,也许是PHP/Hacklang的不好的例子,因为它不是这个低级别,但你明白了.)

linear-types hacklang

3
推荐指数
1
解决办法
149
查看次数

如何在 hacklang 中定义空的 dict<string, int>

我有以下形状:

const type A = shape(
  'b' => dict<string, int>,
);
Run Code Online (Sandbox Code Playgroud)

如何使用空字典创建此形状?例如从这个函数

function getA(): A {
  return shape(
    'b' => ???
  );
}
Run Code Online (Sandbox Code Playgroud)

hacklang

3
推荐指数
1
解决办法
3827
查看次数

Hacklang教程 - 扩展类中的这种类型

什么是黑客教程练习16的正确答案?
链接到教程:Hacklang教程

我的修改后的代码(未标记为解决方案):

<?hh
// The type 'this' always points to the most derived type
class MyBaseClass {
  protected int $count = 0;

  public function add1(): this {
    $this->count += 1;
    return $this;
  }
}

class MyDerivedClass extends MyBaseClass {
  public function print_count(): void { echo $this->count; }
}

function test(): void {
  $x = new MyDerivedClass();
  $x->add1()->print_count();
}
Run Code Online (Sandbox Code Playgroud)

我换过MyBaseClass通过this,但仍然没有被标记为正确的(绿色文本与Exercice号)..什么是正确的答案?

php facebook hacklang

2
推荐指数
1
解决办法
532
查看次数

Hacklang是一种有状态还是无状态的语言?

最近,Facebook发布了一种名为Hacklang的新语言,该语言由HHVM编译为机器代码.

所以我只是想知道,Hacklang只是一种有状态的语言吗?

谢谢.

stateful stateless hacklang

2
推荐指数
1
解决办法
582
查看次数

Hack语言:集合类型的泛型

为什么这段代码有效?

<?hh // strict
function test(Vector<int> $v):void {
    print_r($v);
}

test(Vector {1, array("I'm an array"), 3});
Run Code Online (Sandbox Code Playgroud)

它不应该抛出错误吗?什么是<int>应该的?

generics hhvm hacklang

2
推荐指数
1
解决办法
316
查看次数

HackLang by Facebook并不严格

美好的一天,

我有问题.我想在hacklang中模拟一些错误.

<?hh
namespace Exsys\HHVM;

class HHVMFacade{

    private $vector = Vector {1,2,3};

    public function echoProduct() : Vector<string>{
        return $this->vector;
    }

    public function test(Vector<string> $vector) : void{
        var_dump($vector);
    }

}
Run Code Online (Sandbox Code Playgroud)

函数echoProduct()返回字符串的Vector.但私有财产$ vector是整数的向量.当我调用echoFunction并返回值用作函数test()的参数时.我明白了

object(HH\Vector)#35357 (3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
Run Code Online (Sandbox Code Playgroud)

为什么?我期待一些错误,因为类型不匹配.

hhvm hacklang

2
推荐指数
1
解决办法
229
查看次数

如何让XHP在Ubuntu上运行hack/hhvm

我已经按照网站上的说明安装了hack-nightly并使用nginx设置了fastcgi,但是在尝试创建使用xhp的简单文件时出现错误:

<?hh
$x = <html><body>hello</body></html>;
echo $x->toString();
Run Code Online (Sandbox Code Playgroud)

错误:

Fatal error: Class undefined: xhp_html in /
Run Code Online (Sandbox Code Playgroud)

我需要采取一个步骤来启用此功能,还是需要安装其他导入或包?

xhp hacklang

1
推荐指数
1
解决办法
1243
查看次数

用于 Hack IDE 的 Visual Studio 代码?

您如何看待用于编程 Hack 的 Visual Studio 代码?如果是这样,为什么?我问是因为他的语法错误系统方法,因为我找不到关于这种语言的基本信息。

我看到只有 Visual Studio 代码和 vim,但我想你们是否还有另一个代码,所以我不确定。

hhvm hacklang visual-studio-code

1
推荐指数
1
解决办法
424
查看次数

如何在hacklang中迭代形状的字段?

说我有这样的形状

$something = shape(
  'some_key' => ...,
  'another_key' => ...,
  ...
);
Run Code Online (Sandbox Code Playgroud)

如何迭代形状的每个字段?我正在寻找这样的东西

foreach ($something as $key) {
  ...
}
Run Code Online (Sandbox Code Playgroud)

hacklang

1
推荐指数
1
解决办法
213
查看次数

Hacklang 意外的接口错误

我正在学习 hacklang,并且在不同文件中使用界面时遇到问题。这是我的代码。

IpAuthorizedController.php

<?hh
namespace App\Controller\Interface;

interface IpAuthorizedController {

}
Run Code Online (Sandbox Code Playgroud)

HomeController.php

<?hh
namespace App\controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use App\Controller\Interface\IpAuthorizedController;

class HomeController extends Controller
{
  /**
   * @Route("/", name="index")
   *
   */
  public function index()
  {
    die(var_dump(return $this->render('index.html.twig')));
  }
}
Run Code Online (Sandbox Code Playgroud)

错误信息

FatalThrowableError

syntax error, unexpected T_INTERFACE, expecting '{'
in HomeController.hh (line 5)
Run Code Online (Sandbox Code Playgroud)

我是这门语言的新手,因此非常感谢任何帮助,谢谢。

php hhvm hacklang

0
推荐指数
1
解决办法
528
查看次数