I8, u8, i16, u16, i32, u32 arrays

In my limited understanding, OCaml has int/float types. It, afaik, does not allow me to specify arrays of u8, i8, u16, i16, u32, i32.

This is a problem, as I want to specify them in WebGL buffers / arrays.

Looking at the jsoo webgl example, I see it uses float32 arrays: js_of_ocaml/webgldemo.ml at master · ocsigen/js_of_ocaml · GitHub

What I am curious is whether there is a straight forward way to do arrays of u8/i8/u16/i16/u32/i32.

Thanks!

Straightforward, not exactly, but you can create buffers with u8, i8, etc.: OCaml library : Buffer

There is also stdint, but if you’re looking for “true” n-bit integer types that’s probably going to have to come from the FFI.

Specifically for the TypedArrays you allude to, the Js_of_ocaml library has bindings to (I think) all of them.

That’s typically what Bigarrays are for.

2 Likes