What libraries are missing?

What libraries are missing in the ecosystem, for you? Any libraries - essential and non essential ones also.

3 Likes

MQTT and gRPC are things that would be nice for working with services.
I know there has been movement on gRPC lately but I still don’t know of any MQTT effort.

1 Like

Hmm? There’s an MQTT client library at least. I use it to control my water heater.

Which library if I may ask?

@anuragsoni pointed out this library to me in private: https://github.com/odis-labs/ocaml-mqtt

1 Like

For me its mainly database related things. Like something to do low latency writes to disk in a write-ahead-log fashion.

Which [mqtt] library if I may ask?

I use this one: GitHub - ekoeppen/mqtt_client: MQTT client written in OCaml

Hasn’t it been abandoned?

Hi! I’m the maintainer of odis-labs/ocaml-mqtt package.

The library implements the MQTT client protocol with QoS levels 0 and 1 (2 is currently missing and is arguably less useful). I used it in a production setting to serve up to 20 million events per day without any issues. There’s still some work to make it feature complete and reliable, but I think it’s a good foundation.

Feel free to try it out and let me know what’s missing :slight_smile:

6 Likes

It’s not so much that libraries are missing, as the documentation to use those libraries is missing.

1 Like

most recently I could not find a NATS client

Also high quality native compression libraries instead of the wrappers for the system libs:

4 Likes

It’s a niche interest but I would be happy about a library that can parse FIT files (popular for fitness data) files. The workaround is to parse GPX files, another popular format, which is based on XML.

1 Like

I started something myself: https://github.com/lindig/fit

5 Likes

A big one that’s missing: a decimal data type. .NET (i.e. C#/VB.Net/F#) has the built-in type decimal, Java has BigDecimal, etc. It’s the obvious and only reasonable way to deal with monetary calculations.

Previously:

Edit: a little surprising to have this gap in OCaml, with OCaml being so ‘popular’ in the fintech world…

3 Likes

Jane Street has a Bigdecimal type (based on Zarith), which I think we would be happy to open source if there was interest.

y

15 Likes

That would be very kind of you all. I was playing around with libgmp decimal floats yesterday and, it looks quite tricky to bind to! At least to my untrained eye.

Well, the fates have a sense of humour. Scrolling Twitter randomly today I come across this thread about floating-point errors in calculating French taxes.

That led me to this PR in the Mlang project, which is a domain-specific language created by the French Government for French tax calculations … and implemented in OCaml: https://gitlab.inria.fr/verifisc/mlang

Which led me to a complete set of OCaml bindings to libgmp, including floats.

Exploring this now…

4 Likes

So I’ve been exploring the mlgmpidl library’s bindings to MPFR, but it seems to be a radix-2 representation as well, not a decimal:

# #require "gmp";;
# Mpfrf.to_string (Mpfrf.add (Mpfrf.of_string "0.1" Near) (Mpfrf.of_string "0.2" Near) Near);;
- : string = "0.30000000000000004E0"

(I believe Near is the banker’s rounding or half-even rounding method)

By contrast to Java or Scala BigDecimal:

scala> BigDecimal("0.1") + BigDecimal("0.2")
res0: scala.math.BigDecimal = 0.3

The author of the thread seems to think so too: https://twitter.com/DMerigoux/status/1322551498799226884

1 Like

I should mention, you might want to try out Bignum. It’s not exactly a decimal representation, since it can’t ensure that things are always representable as decimals. But it does some of what you might want.

open! Core
open Bignum.O

let pr x = print_endline (Bignum.to_string_accurate x)

let%expect_test "" =
  (* Be careful about how you convert floats to decimals! You don't
     really want the precise one most of the time. *)
  pr @@ Bignum.of_float_dyadic 0.3;
  [%expect {| 0.299999999999999988897769753748434595763683319091796875 |}];
  pr @@ Bignum.of_float_decimal 0.3;
  [%expect {| 0.3 |}];
  (* But now that you have the right way of importing them, you can
     add and compute and it should all work fine *)
  let d = Bignum.of_float_decimal in
  pr (d 0.1 + d 0.3);
  [%expect {| 0.4 |}];
  (* But what about things that don't have a precise representation as
     a decimal?  Well, Bignum gives you a precise rational
     representation instead. *)
  pr (d 1. / d 3.);
  [%expect {| (0.333333333 + 1/3000000000) |}];
  (* You can ask for a decimal representation, but it will fail
     sometimes. *)
  print_s [%sexp (Bignum.to_string_decimal_accurate (d 1. / d 3.) : string Or_error.t)];
  [%expect {| (Error ("Not representable as decimal" (0.333333333 + 1/3000000000))) |}]
;;
2 Likes