Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> need random access.

I was thinking quite the opposite, I admit I don't know much about OCaml yet but I was very interested in trying ReasonML. Anyways, I would think you would use an array when you need sequential access and potentially help locality of reference when doing some number crunching? OCaml arrays are random access?



By random-access he means O(1) indexing, unlike lists. Yes, arrays works the same(but there is bounds-checking).


> you would use an array when you need sequential access and potentially help locality of reference when doing some number crunching

Yes, that's what float arrays were specialized for. From a quick glance at the OCaml compiler code, you might also get effective locality with other unboxed types (ints, chars). Boxed types will likely require an additional lookup even if the values are allocated contiguously. But if you're at the point of being concerned with memory access patterns, then bigarrays will probably work better.

If all you need is sequential access, then a list is much more convenient to use.

I'm not sure how all this translates to ReasonML though, as the JS runtime is very different.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: