tjammer / raylib-ocaml

OCaml bindings for raylib and raygui
https://tjammer.github.io/raylib-ocaml/
MIT License
175 stars 14 forks source link

[Feature request] Purely functional setters for Raylib structures #5

Closed Lattay closed 4 years ago

Lattay commented 4 years ago

While implementing examples in PR #3 I end up doing a lot of creation of fresh Raylib objects, notably vectors and camera. I was wondering if it would be possible to add purely functional setters that would be a bit more efficient in returning a new object with some parameters changes, maybe by using the copy-on-write facilities from OCaml ?

I am not seasoned enough in OCaml to tell whether such a thing is possible but I think it would be great because right now, I am pretty sure the compiler cannot tell that the new camera I am allocating should replace the old one.

tjammer commented 4 years ago

I don't think a functional setter like with records is possible, b/c the Raylib types are opaque to the compiler (but I'd be happy to be proven wrong). I implemented setters for some types to reuse the C objects, like here or here. They don't return the new objects and instead work like setters in an object oriented language.