paurkedal / ocaml-caqti

Cooperative-threaded access to relational data
https://paurkedal.github.io/ocaml-caqti/index.html
GNU Lesser General Public License v3.0
299 stars 36 forks source link

Eio: stdenv type not compatiable with Eio_unix.Stdenv #114

Closed ada2k closed 6 months ago

ada2k commented 6 months ago

Hi, The ~stdenv argument taken by caqti-eio does not appear to be compatible with Eio_unix.Stdenv. If I manually create an object with the net, clock and mono_clock methods copied from Eio_unix.Stdenv, it then throws a type error expecting [Generic] instead of [Generic | Unix]. Editing system.ml to accept [Generic | `Unix ] allows me to connect to a postgres instance fine. I have caqti pinned to master with eio 0.14, not tested on release. Thank you

paurkedal commented 6 months ago

I assume you are seeing a compile-time error related to the net component of the environment containing additional `Unix functionality. In general if you have an environment which is richer than needed, you can restrict it with (myenv :> Caqti_eio.stdenv) before passing it, which should also work here.

ada2k commented 6 months ago

Thank you! I'm not too familiar with classes, so sorry for wasting your time.

paurkedal commented 6 months ago

No problem; it's one of the lesser known parts of the language. Maybe the preferred way would have been to pass the three resources individually, though I think the current approach of bundling them provides a better chance of programs being compatible with new versions of Caqti which might require extra resources from the stdenv.

ada2k commented 6 months ago

I know caqti-eio is prerelease, but would it's API be stable enough to receive some documentation? I would be happy to translate the bikereg example from Lwt. I think Eio can present unfamiliar elements to more people than me (especially with it's use of the class system), so a simple 1-1 demonstration of an lwt program would be useful.

paurkedal commented 6 months ago

Yes, I realized some documentation is needed here. I will add some basics to the API doc. The caqti-study is maybe a better place for examples. I have considered moving the bikereg there, as well. We should coordinate that with @benjamin-thomas who has done most of the current work there.

benjamin-thomas commented 6 months ago

Sounds good to me :+1:

I've opened an issue to track this. We can discuss there if you feel like giving a hand @ada2k