Is there something similar to Clojure's spec library in OCaml?

Is there something similar to Clojure’s spec library in OCaml?


The spec library is designed for describing, validation and generation of different data structures. Here is a description of this library: https://clojure.org/guides/spec

It might be useful to give an overview of what that library does, for people who are not familiar with it to be able to tell if there’s anything similar for OCaml.

2 Likes

It uses for describing, validation and generation of different data structures. Here is a description of this library: https://clojure.org/guides/spec

I think the closest thing to spec is http://c-cube.github.io/qcheck/0.8/qcheck/QCheck/index.html

2 Likes

There are some zipper libs. Not the same thing, but able to do the same work in the end in a different way.

This isn’t exactly equivalent, but I tend to use ppx_deriving_yojson for this. Rather than writing clj specs for my JSON requests, I automatically derive the json decoder from the type.

Upsides:

  • very easy to write, much easier than clj-spec

Downsides:

  • not as powerful
  • limited use case of HTTP/JSON (or other serializers) rather than arbitrary objects (though I’d argue types work for that)
  • poor error messages
1 Like

Oh sorry–zippers are nothing at all related to spec. Was thinking of something else. Must have been too late at night.

1 Like