companion_cube changed the topic of #ocaml to: Discussions about the OCaml programming language | http://www.ocaml.org | OCaml 4.11 release notes: https://caml.inria.fr/pub/distrib/ocaml-4.11/notes/Changes | Try OCaml in your browser: http://try.ocamlpro.com | Public channel logs at http://irclog.whitequark.org/ocaml
mxns has joined #ocaml
Tuplanolla has quit [Quit: Leaving.]
mxns has quit [Ping timeout: 246 seconds]
theblatte has joined #ocaml
mxns has joined #ocaml
mxns has quit [Ping timeout: 272 seconds]
dhil has quit [Ping timeout: 240 seconds]
mxns has joined #ocaml
mxns has quit [Ping timeout: 260 seconds]
larou has quit [Quit: Connection closed]
worc3131 has quit [Ping timeout: 272 seconds]
_whitelogger has joined #ocaml
larou has joined #ocaml
larou has quit [Client Quit]
nullcone has joined #ocaml
jbrown has quit [Ping timeout: 246 seconds]
<d_bot> <Criss> How do we do the following in ocaml. i am quite confused
<d_bot> <Criss>
<d_bot> <Criss> Write an expression that computes 4.2 raised to the seventh power.
<companion_cube> 4.2 ** 7.
<d_bot> <Criss> oh thanks
<d_bot> <Criss> but that only seems to work with floats right?
<d_bot> <Criss> what bout ints?
<companion_cube> ah, well, 4.2 isn't an int
<companion_cube> (for ints you'd have to define a int power function, or use a library that defines it
<d_bot> <mbacarella> `base` has `Int.pow x n` that evaluates to x^n
<companion_cube> containers has the same, it's a classic
ansiwen has quit [Quit: ZNC 1.7.1 - https://znc.in]
ansiwen has joined #ocaml
<d_bot> <beheddard> I'm having trouble finding the way to add a C library to dune so I don't have to use `Dl.dlopen` and `foreign ~from:`
<d_bot> <beheddard> in Ctypes
<d_bot> <EduardoRFS> anyone knows if merlin can somehow finds the usages of a value across files??
narimiran has joined #ocaml
jnavila has joined #ocaml
ggole has joined #ocaml
mxns has quit [Ping timeout: 246 seconds]
reynir1 has joined #ocaml
reynir has quit [Ping timeout: 240 seconds]
reynir1 is now known as reynir
jnavila has quit [Quit: Konversation terminated!]
yomimono has quit [Ping timeout: 256 seconds]
yomimono has joined #ocaml
mxns has joined #ocaml
<d_bot> <rgrinberg> It's not possible.
<d_bot> <rgrinberg> Or rather, merlin doesn't do it
mxns has quit [Ping timeout: 272 seconds]
<d_bot> <EduardoRFS> @rgrinberg do you know if there is any issue on that? I want to know what is the plans
<d_bot> <rgrinberg> In the trivial case, it's fairly simple. Functors complicate the crap out of it. Odoc has a fairly complete implementation of this
<d_bot> <beheddard> Alright seems like it was my own mistake not adding `ctypes.foreign` to my dune file that was causing `dune utop` to fail loading. I am still finding getting into static linking of a C library a bit daunting. Do I need to go the full Ctubs route?
<d_bot> <beheddard> The handful of functions that I have tried out while it is dynamically linking via `Dl` are working, but I'd like to figure out how to get it compiled. Do I have to go the distance and learn the full setup described here: https://github.com/cedlemo/ctypes-stubs-generation-notes ? Or is there a simpler way I have not come across yet?
<d_bot> <rgrinberg> @beheddard are you creating a library for other people to use?
lopex has joined #ocaml
osa1 has joined #ocaml
<d_bot> <beheddard> Yes I'm writing bindings for the Olm encryption library as part of my matrix client project
<d_bot> <rgrinberg> I'd say you should generate stubs. Your library will be much less fragile if it doesn't use libffi
<d_bot> <rgrinberg> That's without even consider performance issues.
<d_bot> <beheddard> Ah yes I was wondering about performance as well but hadn't see anyone talk about that yet
<d_bot> <mnxn> I recommend using https://github.com/fdopen/ppx_cstubs for a PPX wrapper over cstub generation.
<d_bot> <mnxn> cstub generation is much better since you get compile time errors if you incorrectly bind a library.
<d_bot> <rgrinberg> The ppx is nice, although I'd recommend to have an understanding of the low level details.
<d_bot> <beheddard> I hadn't heard of that ppx before. I've already slogged through all of the `foreign` boilerplate with Ctypes though
<d_bot> <beheddard> It seems like for the most part the code around the bindings themselves is simple when it comes to Cstubs, but the extra stuff concerning building and the dealing more intimately with dune is a bit overwhelming having never done something that required more than listing libraries in dune files haha
mxns has joined #ocaml
<d_bot> <rgrinberg> Indeed. You just keep in mind that what you write with ctypes is just going to be used in the build step to generate the stubs.
mxns has quit [Ping timeout: 260 seconds]
<d_bot> <rgrinberg> This is why it's a little more involved.
<d_bot> <beheddard> Yea, it's going to take some study on my end then. So is it necessary to use a `discovery.ml` as in the example repo I linked in order to link up the generated stubs with the C library? The third example is the first time I've seen it included while reading about Cstubs.
<d_bot> <beheddard> I guess part of the conceptual gap is how much of the stuff in the example I need to be copying and slotting my own paths in etc
Haudegen has joined #ocaml
<d_bot> <rgrinberg> `discover.ml` is only needed if the flags are static. In other words, you don't need to build run any code to know what they are
<d_bot> <rgrinberg> For some C libraries, you need to use `pkg-config` to know these flags. I'm not sure the details of your C library.
<d_bot> <beheddard> Ok, so I'll need to refer to the cmakelist etc and port those steps over into dune?
<d_bot> <rgrinberg> Are you planning to build the C library as well in dune?
<d_bot> <beheddard> Compiling the library as part of my build, rather than using a compiled .so
<d_bot> <beheddard> I'm not sure, was hoping to get an idea
<d_bot> <beheddard> Sorry my C experience is non existent and I've only used C++ for research simulations, leaning heavily on Clions handling of cmakelists haha
<d_bot> <rgrinberg> You don't have to port the build from cmake to dune. You could also just tell dune to run a makefile (or any other action) to build an archive
<d_bot> <beheddard> Ahh ok, that answers one question
<d_bot> <beheddard> So in that case, would I need to be coordinating with a discovery.ml, or it's not enough context to know
borne has joined #ocaml
<d_bot> <rgrinberg> If you're building the C library in dune, you don't need discover.ml
<d_bot> <rgrinberg> If you aren't using an external C library, you don't need to run pkg-config.
<d_bot> <beheddard> External meaning what in this context? Not a global library that needs to be discovered?
<d_bot> <beheddard> So I'd be in the pkg-config box?
<d_bot> <rgrinberg> External means external to your dune workspace.
<d_bot> <rgrinberg> Usually installed via some system package manager
<d_bot> <rgrinberg> Running `$ pkg-config --list-all` might help you understand
<d_bot> <beheddard> Oh ok, so my installed packages on Arch in bin etcetera. If I have a repo in parallel to my binding one that I pull, then run make on, would that be external to the workspace because it isn't under the dune project root?
<d_bot> <rgrinberg> Yes
<d_bot> <rgrinberg> External = dune does not build the library, it must use the library's archives from elsewhere.
<d_bot> <rgrinberg> If you're familiar with ocamlfind, there's a useful analogy. ocamlfind is what used to find the library archives for ocaml libraries. pkg-config is the same for C/C++ libraries
<d_bot> <beheddard> Ah ok. Then if I just have dune call make on the C library in a parallel directory, I'll need pkg-config (and / with discover.ml, or I simply run pkg-config from the dune file?). And if I ported the make process into dune, then it would be internal and I would not need it?
<d_bot> <beheddard>
<d_bot> <beheddard> Thanks for this discussion by the way, it's helping me to find out what I'm wrong about much sooner!
<d_bot> <rgrinberg> You will need to build the library, and install it. hopefully that will make it show up in `pkg-config`.
<d_bot> <rgrinberg> Just to clarify this once again:
<d_bot> <rgrinberg> * external library: dune does not know about the library's source - only where the already built .a files are.
<d_bot> <rgrinberg> * internal library: dune knows how to build the .a from the source - by running make or using its own C rules.
<d_bot> <beheddard> Ahh alright I didn't make the connection on installing it system wide to get it to appear in pkg-config. I feel it would be better to not require that (especially for down the road), so that the process is more contained and doesn't need to move outside of the repo folders. Or am I wrong and I shouldn't care? To clarify then, dune can't / shouldn't be used to make the library if it's parallel to the dune root, or if it can, it
<d_bot> <beheddard> I feel like I'm probably being dumb now that it's 1AM here
emp has quit [Quit: ZNC 1.8.1 - https://znc.in]
berberman_ has quit [Ping timeout: 260 seconds]
Anarchos has joined #ocaml
berberman has joined #ocaml
emp has joined #ocaml
Anarchos has quit [Client Quit]
Anarchos has joined #ocaml
jbrown has joined #ocaml
olle has joined #ocaml
reynir has quit [Ping timeout: 256 seconds]
hnOsmium0001 has quit [Quit: Connection closed for inactivity]
reynir has joined #ocaml
olle has quit [Read error: Connection timed out]
olle has joined #ocaml
reynir has quit [Excess Flood]
reynir has joined #ocaml
orbifx has joined #ocaml
Anarchos has quit [Quit: Vision[0.10.3]: i've been blurred!]
mxns has joined #ocaml
mxns has quit [Ping timeout: 260 seconds]
reynir has quit [Ping timeout: 256 seconds]
reynir has joined #ocaml
osa1 has quit [Remote host closed the connection]
jbrown has quit [Quit: Leaving]
mxns has joined #ocaml
mxns has quit [Ping timeout: 246 seconds]
zolk3ri has quit [Ping timeout: 240 seconds]
dhil has joined #ocaml
reynir has quit [Ping timeout: 256 seconds]
zolk3ri has joined #ocaml
reynir has joined #ocaml
bartholin has joined #ocaml
Serpent7776 has quit [Read error: Connection reset by peer]
Serpent7776 has joined #ocaml
reynir has quit [Ping timeout: 264 seconds]
reynir has joined #ocaml
bartholin has quit [Quit: Leaving]
Haudegen has quit [Quit: Bin weg.]
reynir has quit [Ping timeout: 258 seconds]
reynir has joined #ocaml
sleepingisfun has quit [Quit: hewwo]
reynir has quit [Ping timeout: 256 seconds]
reynir has joined #ocaml
orbifx has quit [Ping timeout: 258 seconds]
orbifx has joined #ocaml
mbuf has joined #ocaml
orbifx has quit [Ping timeout: 265 seconds]
Haudegen has joined #ocaml
reynir has quit [Ping timeout: 264 seconds]
Anarchos has joined #ocaml
reynir has joined #ocaml
borne has quit [Ping timeout: 260 seconds]
borne has joined #ocaml
jbrown has joined #ocaml
Anarchos has quit [Quit: Vision[0.10.3]: i've been blurred!]
mxns has joined #ocaml
mxns has quit [Ping timeout: 264 seconds]
ski has quit [Ping timeout: 260 seconds]
ski has joined #ocaml
mbuf has quit [Ping timeout: 272 seconds]
Deknos has joined #ocaml
mxns has joined #ocaml
orbifx has joined #ocaml
berberman_ has joined #ocaml
berberman has quit [Ping timeout: 272 seconds]
berberman_ has quit [Max SendQ exceeded]
berberman has joined #ocaml
berberman has quit [Max SendQ exceeded]
berberman has joined #ocaml
berberman has quit [Max SendQ exceeded]
berberman has joined #ocaml
orbifx has quit [Ping timeout: 272 seconds]
smazga has joined #ocaml
Tuplanolla has joined #ocaml
<d_bot> <mbacarella> speaking of cstubs, is there a good minimal example of using cstubs with a random library to access functions and global values in Foobar where you have to generate the `#include <foobar.h>`? i struggled hard to find one and had to adapt what's being done in `luv`. it's still about 56 lines of `dune` file which feels like a lot
tane has joined #ocaml
mxns has quit [Ping timeout: 246 seconds]
Haudegen has quit [Quit: Bin weg.]
hnOsmium0001 has joined #ocaml
mxns has joined #ocaml
borne has quit [Ping timeout: 265 seconds]
reynir1 has joined #ocaml
reynir has quit [Ping timeout: 265 seconds]
reynir1 is now known as reynir
olle has quit [Ping timeout: 256 seconds]
jbrown has quit [Ping timeout: 272 seconds]
mbuf has joined #ocaml
jbrown has joined #ocaml
delysin has quit [Quit: WeeChat 2.9]
delysin has joined #ocaml
ggole has quit [Quit: Leaving]
Haudegen has joined #ocaml
<d_bot> <craigfe> @mbacarella: Here's one for `libfiu` in 35 lines, which is maybe still a lot depending on your perspective (https://github.com/CraigFe/ocaml-fiu/blob/main/src/fiu/ffi/dune). I'm not aware of any way to reduce it further.
<d_bot> <mbacarella> > @mbacarella: Here's one for `libfiu` in 35 lines, which is maybe still a lot depending on your perspective (https://github.com/CraigFe/ocaml-fiu/blob/main/src/fiu/ffi/dune). I'm not aware of any way to reduce it further.
<d_bot> <mbacarella> @craigfe i think that only generates functions and not constants? add 20 lines to include that 😛
<d_bot> <craigfe> There are header includes as part of the stub generator
<d_bot> <mbacarella> by "generates constants" i mean being able to access global constants in the header via ml. to do that i need a separate pass that functorizes over interface Ctypes.TYPE instead of Ctypes.FOREIGN
<d_bot> <mbacarella> basically what antron does here: https://github.com/aantron/luv/blob/master/src/c/luv_c_type_descriptions.ml
<d_bot> <craigfe> I forgot that there was a `constant` term in Ctypes, cool.
<d_bot> <craigfe> Looks like you're stuck with your ~50 lines then
<d_bot> <mbacarella> sigh can't i have a dune stanza that does all of this magic for me
<d_bot> <craigfe> one day
<d_bot> <craigfe> (The answer is probably: if you're willing to implement the Dune stanza yourself, sure you can 😉)
<d_bot> <mbacarella> the devil is in the details i guess. where are the headers at? where are the libraries at? do you want to statically or dynamically link? or will you *runtime* dynamically link?
<d_bot> <mbacarella> @craigfe funny, i had actually come across that open issue a few months ago looking for a minimal example. so, to help future people i'm going to link your lib there in the comments 😛
borne has joined #ocaml
<d_bot> <beheddard> What is the preferred / best practice layout / arrangement for a binding library using someone elses C library? Didn't get to asking that specific question last night.
emp has quit [Remote host closed the connection]
emp has joined #ocaml
<d_bot> <beheddard> Should I have the C repo (not forked) within my ocaml repo (gitignored) so that dune can pull build it as an interal library?
<d_bot> <beheddard> Or should I have it in a parallel directory, build it separately, then link it as an external library?
orbifx has joined #ocaml
Deknos has quit [Ping timeout: 260 seconds]
Deknos has joined #ocaml
<d_bot> <mbacarella> a thing i use on a few projects now is i create a setup-project.sh script that downloads dependencies like that directly into my repo
<d_bot> <mbacarella> with .gitignores set up so they're ignored, of course
<d_bot> <mbacarella> (setup-project.sh also does things like create an opam local switch just for the project)
<d_bot> <beheddard> ah ok, so just opting to avoid any git mess that could result from pulling the repo directly
<d_bot> <beheddard> downloading the zip and unpacking instead?
mbuf has quit [Quit: Leaving]
hannes has quit [Ping timeout: 260 seconds]
sm2n has quit [Read error: Connection reset by peer]
sm2n_ has joined #ocaml
hannes has joined #ocaml
berberman_ has joined #ocaml
berberman has quit [Ping timeout: 272 seconds]
gareppa has joined #ocaml
gareppa has quit [Remote host closed the connection]
borne has quit [Ping timeout: 272 seconds]
orbifx has quit [Read error: Connection reset by peer]
orbitalfox has joined #ocaml
orbitalfox is now known as orbifx
<d_bot> <beheddard> Looking through the Luv type bindings, he seems to define the ocaml types inside the same module as the corresponding C ones (within the stubs functor)
<d_bot> <beheddard> Are there tradeoffs to doing that, compared to having them outside like in https://github.com/cedlemo/ctypes-stubs-generation-notes ?
narimiran has quit [Ping timeout: 258 seconds]
osa1 has joined #ocaml
<d_bot> <stab> Anybody know anything gherkin like for testing in Ocaml? I guess it would be kinda pointless since there isn’t much point for your functional components
<orbifx> ;)
<orbifx> stab is that for unit tests?
<d_bot> <stab> It’s for like behavior bases stuff so like you define steps in your target language that then get related to specs of the form “GIVEN blah, WHEN i do blah, THEN x should be the state”
<d_bot> <stab> So like your actual tests are in a sorta readable text format
<d_bot> <stab> Like this https://pypi.org/project/pytest-bdd/
<d_bot> <stab> I find it kinda nice tbh , ppl don’t like it tho
<orbifx> had a look on opam, using relevant keywords?
<orbifx> there are some test automation modules
<d_bot> <stab> Yeah I didn’t find anything substantially similar, when you look for bdd it’s all binary decision diagrams lol
<d_bot> <Anurag> @stab i've seen https://github.com/cucumber/cucumber.ml on github before. There are recent commits so it looks like its maintained .
<d_bot> <stab> Oh yeah that looks like exactly what I’m looking for
<d_bot> <stab> Thanks!
borne has joined #ocaml
reynir has quit [Ping timeout: 272 seconds]
reynir has joined #ocaml
Deknos has left #ocaml [#ocaml]
larou has joined #ocaml
tane has quit [Quit: Leaving]
osa1 has quit [Remote host closed the connection]
<d_bot> <rgrinberg> > Looking through the Luv type bindings, he seems to define the ocaml types inside the same module as the corresponding C ones (within the stubs functor)
<d_bot> <rgrinberg> @beheddard Having them outside is usually more convenient. You can use the types without going through functor application. Although it's probably irrelevant in this case.
Serpent7776 has quit [Quit: leaving]
vicfred has joined #ocaml
aaaaaa has joined #ocaml
orbifx has quit [Ping timeout: 256 seconds]
unihernandez22 has joined #ocaml
unihernandez22 has quit [Remote host closed the connection]
<d_bot> <beheddard> Since the code actually used in the end is generated from the functor application, there isn't a practical difference basically?
<d_bot> <rgrinberg> Probably not in this case.
<d_bot> <beheddard> Ok, thanks! I'll leave it outside where it is for now, then compare after it's actually compiling I guess.
aaaaaa has left #ocaml [#ocaml]
larou has quit [Quit: Connection closed]
borne has quit [Ping timeout: 260 seconds]
Haudegen has quit [Ping timeout: 256 seconds]
Tuplanolla has quit [Quit: Leaving.]
dhil has quit [Ping timeout: 240 seconds]
CcxWrk has quit [Ping timeout: 260 seconds]
CcxWrk has joined #ocaml
CcxWrk has quit [Excess Flood]
CcxWrk has joined #ocaml
<d_bot> <beheddard> So, I'm trying to navigate the type stub generation right now, *sort of* following the way Luv does it. I've got the `foreign_archives` pointed at a static archive produced by the C libraries make.
<d_bot> <beheddard> It seems to find that fine (since the wrong name causes it to terminate), but when I try to inlcude the headers that should be in the archive, they are not found.