In HJavaScript there is the Array
type, but I can't see a way of constructing a literal that would translate, for example, to JS as [1,2,3]
. I don't want to have to create a new Array()
and then push items into it, if I don't have to.
Ideally I'm after a function like array :: [t] -> Array t
.
I could possibly use JConst
to implement array
, but it seems like a hack for something that should be straight-forward. I could also do the create-and-push method above to implement array
, this is also not great, though.
Here is array
by pushing; not so great.
array :: [Exp a] -> JS (JArray a)
array xs = do
arr <- new Array ()
mapM_ (`push` arr) xs
return arr
This question is the first I've heard of HJscript. Briefly looking at the docs, I can't see any way to make a simple array literal like [1,2,3]
. But, I do see a way to call functions, and note that [1,2,3] = Array(1,2,3)
. In fact, I'll bet interpreters treat the former as sugar for the latter. So if you can call functions, you can construct literals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With