How do you create array literals using HJScript or, indeed, HJavaScript?

HJavaScript has an Array type , but I don’t see a way to build a literal that would translate, for example, JS as [1,2,3] . I do not want to create new Array() and then insert elements into it if I do not need it.

Ideally, I execute a function like array :: [t] -> Array t .

I could use JConst to implement Array , but it seems to hack something that should be straight forward. I could also make the create-and-push method higher to implement Array , but that is also not very convenient.

Here is the Array by clicking; not so good.

 array :: [Exp a] -> JS (JArray a) array xs = do arr <- new Array () mapM_ (`push` arr) xs return arr 
+6
source share
1 answer

This question is the first that I heard about HJscript. Looking at the documents briefly, I see no way to make a simple array literal as [1,2,3] . But I see a way to call functions and note that [1,2,3] = Array(1,2,3) . In fact, I will bet that translators view the former as sugar for the latter. Therefore, if you can call functions, you can create literals.

+2
source

Source: https://habr.com/ru/post/887524/


All Articles