OCaml Weekly News
Hello
Here is the latest OCaml Weekly News, for the week of January 22 to 29, 2019.
Table of Contents
ocaml-gemini 0.1
Carmelo Piccione announced
Hello, I'd like to announce the initial release of ocaml-gemini, a pure OCaml library that fully implements the Gemini REST api as well as market data and private order events websocket apis.
For those unfamiliar, Gemini is a well established cryptocurrency exchange launched by the notorious Winklevoss Twins (unfortunately the exchange is written in Go, but I digress).
The implemention depends on cohttp-async
, websocket-async
, and yojson
for serialization support. nocrypto
is used for the session authentication. If there is sufficient interest by the community I can extend the code to support a lwt
version.
A console interface is also provided which accepts s-expressions as parameters. It is mostly used to test the api or do quick and dirty order management.
Finally, any feedback on the api or PRs are welcome, as usual.
Godbolt compiler explorer beta now has OCaml support
Freyr666 announced
Feel free to test.
Debugging memory issues
Sean Talts asked
I'm working on a new compiler/transpiler written in OCaml and we've (unfortunately?) been using the Format library to emit the code that we're generating. Today I'm just starting to run it on some huge test programs and finding that it's taking up dozens of GB of memory pretty quickly and totally swamping the machine only a little ways into the program. I tried debugging with ocamldebug
but I can't find any specific code that's repeating too much or anything like that - it just seems like something invisible is happening and my number one suspect is that it's the building up of these long Format strings (with nested "%a" compositional formatting). But I'd like to figure out for sure so I don't waste time switching away from the Format library or something if it's an unrelated issue.
Any help appreciated! Thanks :)
Jack Feser replied
You could give spacetime (https://blog.janestreet.com/a-brief-trip-through-spacetime/) a try. It's a new ocaml memory profiler. You'll need to install a spacetime-specific compiler switch though.
Simon Cruanes then said
In my experience, Format
doesn't leak memory (if you use fprintf
into some IO channel; if you print into a buffer then the buffer might grow, of course). It's pretty fast and very convenient. I second the idea of using some form of profiling such as spacetime to find where the leak comes from.
Christian Lindig replied
I have not used it myself, but Obj.reachable_words
reports the words reachable from a given value. If you suspect some value already to be responsible for the leak, you could observe it with this function.
Pierre Chambart also replied
I have debugged quite a few things with https://github.com/jhjourdan/ocaml/tree/memprof . It is available in the opam repository as ocaml-variants.4.07.1+statistical-memprof you should use it with https://github.com/jhjourdan/statmemprof-emacs
First release of Mssql
Brendan Long announced
I'm happy to announce the first opam release of Mssql, our FreeTDS-based Async SQL Server client library.
We've gone to some trouble to make it safer to use than direct bindings to FreeTDS, with things like parameterized queries, workarounds for insane logic in FreeTDS, and logic to throw exceptions instead of crashing when you try to do things like use a closed DB handle.
We've also wrapped everything in background threads and ensured that any FreeTDS calls that perform IO release the runtime lock, so it's safe to use in an Async app without blocking everything when you do DB calls, and also ensured that if you attempt to use a connection concurrently, everything will just work (although it won't be any faster).
There's also a built-in thread pool, although it has some annoying limitations since FreeTDS doesn't give us low-enough-level control to properly reset connections.
(We made this using Async since that's what we use, but contact me if you want to add support for Lwt)
IFDEF conditional compilation and ocamlbuild
Luc Bougé announced
I am developing a program in Ocaml for my Programming class.This idea is to provide the students with various versions of the program, using more and more complex techniques.
I would like to design a common master, and then derive the various versions automatically using some conditional compilation facility.
I considered camlp4 IFDEF but it applies to complete expressions, only. Instead, I would like to add or remove cases in long lists of if ... then ... else if ...
.
Also, I am using ocamlbuild
and I cannot find how to define IFDEF
compilation tags in the compilation chain.
Is there any IFDEF-wizard in the community? :sunglasses:
Anton Kochkov replied
See https://github.com/ocaml-community/cppo + https://jbuilder.readthedocs.io/en/latest/quick-start.html#using-cppo (for dune, since using plain ocamlbuild is "an old way of doing things").
Anton Kochkov then added
Note there is also https://github.com/janestreet/ppx_optcomp for using only extension points (PPX)
Old CWN
If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.
If you also wish to receive it every week by mail, you may subscribe online.