问题标签 [hacklang]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1634 浏览

php - "walk" a PHP array using multithreaded (async) with hack (HHVM)

Not sure why there isn't yet a "hack" tag (sorry to list in PHP), but...

I am wondering if it/how it would be possible to walk an array using multiple threads using the multithreaded/async feature of hack. I don't really need this, but it is a curiosity and might be useful.

I've looked at the documentation for "Hack"'s async feature

http://docs.hhvm.com/manual/en/hack.async.php

and its a bit difficult.

Here is the basic idea of what I would like to make (or see done):

a) Split up the array into x sections and process it on x "threads" or b) create x threads and each processes the latest available item, ie. when it the thread processes the item, it asks the parent thread for a new one to process. Hack doesn't do "threads", but the same is represented by an asyc function

Basically, the end goal is to quickly optimize a standard foreach block to run on multiple threads, so minimal code change is required, and also to see what hack can do and how it works.

I've come up with some code as a sample, but I think I've totally got the idea wrong.

0 投票
1 回答
321 浏览

hhvm - Facebook 的 HackLang 并不严格

再会,

我有问题。我想模拟hacklang中的一些错误。

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

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

0 投票
1 回答
512 浏览

asynchronous - hacklang 中的异步服务器

我正在尝试在 hacklang 中创建异步服务器。文件名是first.php:

但这不起作用。这段代码上的 hh_client 说:

first.php:16:3,29:此表达式的类型为 Awaitable,但在等待之前它要么被丢弃,要么被以危险的方式使用(Typing[4015])

first.php:20:39,47: 这就是为什么我认为它是 Awaitable

但我不想阻塞等待handleClient。

然后我以这种方式运行代码: hhvm -d hhvm.hack.lang.auto_typecheck=0 first.php

服务器启动。但是,当我开始从浏览器服务器向服务器http://192.168.0.97:8080/发送请求时,在很长一段时间内很少请求并且不再接受新连接。

我做错了吗?是否可以在 hacklang 中创建这样的服务器?

0 投票
1 回答
574 浏览

assertions - Hack 程序员是否使用运行时断言?

在无类型语言中,运行时断言可以捕获“类型错误”:

使用 Hack 的类型注释,我想删除断言,但这是不安全的,因为非类型化代码仍可能调用类型化函数。

对于任何专业的 Hack 开发人员:您是否使用断言强制执行类型签名?(我真的很想知道 Facebook 的政策是什么,但我知道这是否是一个秘密。)

0 投票
1 回答
267 浏览

arrays - Hacklang 集合的高阶函数

Hacklang Collections 是否具有更高阶的函数,例如,Reduce或实现此类方法的简单方法。我最关注的 Collection 是 Vector。它似乎只有和。其他人将有助于编写更干净的功能代码。SomeAllMapFilter

0 投票
1 回答
209 浏览

hacklang - 可捕获的致命错误:Hack 类型错误

来自第 31 页演示的示例

错误

可捕获的致命错误:Hack 类型错误:example.php 第 6 行键入错误

问题是什么?


HipHop VM 3.11.1 (rel)

编译器:标签/HHVM-3.11.1-0-g64d37362bc0b6aee919492ad61cf65ce0a5d5e92

回购模式:8b80ba45250a6669cd610c189dbbb55b6218c2a3

0 投票
1 回答
341 浏览

hacklang - Self/child static construct (hacklang)

Guess it's impossible design for Hacklang?

Can't use new on classname 'Foo'; __construct arguments are not guaranteed to be consistent in child classes (Typing[4060])

0 投票
1 回答
47 浏览

hacklang - 意外的 T_OBJECT_OPERATOR 但没有 TypeChecker 错误 (Hacklang)



两者都适用于类型检查器,但第二个导致致命错误

致命错误:语法错误,意外的 T_OBJECT_OPERATOR,期待 ')'

0 投票
1 回答
624 浏览

hacklang - 泛型和类型转换

这是一个非常简化的例子:

例如,我知道 $values 是数字的,源自数据库获取结果或其他内容,但存储为字符串。所以我想将它们转换为 int through

不支持对象强制转换。尝试“if ($var instanceof Tx)”或“invariant($var instanceof Tx, ...)”。(命名[2055])

getListInt():Vector<int>那么在这种情况下,我应该为不同的类型使用两个函数getListString():Vector<string>吗?或者我确实错过了什么?

0 投票
0 回答
394 浏览

type-inference - 为什么 Hack 不推断可空类型?

Hack 不自动推断可空类型的任何具体原因?相反,您必须?明确编写。如果改为使用推理,它是否也不能检查常规 PHP 程序的空值?

例如,此函数将具有类型bool -> ?string