Bin_io/bin_prot with Core.Sequence?

The API docs for Core_kernel.Sequence say:

This module extends Base.Sequence with bin_io.

I’m trying to figure out how to use bin_prot to serialise Sequence sequences. So far nothing I’ve tried has had success. Is it possible to do this at this point without writing a chunk of bin_prot support code for Sequence? Here are some of the things I’ve tried:

# module C = Core_kernel;;
# #require "ppx_bin_prot";;
# open Bin_prot.Std;;
# open Bin_prot.Common;;
# type t = int C.Sequence.t;;
# C.Sequence.bin_size_t;;
Error: Unbound value C.Sequence.bin_size_t
# type t = int C.Sequence.t [@@deriving bin_io];;
Error: Unbound value C.Sequence.bin_shape_t

The only reference I can see to bin_io in the source files and sequence.mli in the core_kernel repo is for the submodule Core_kernel.Sequence.Merge_with_duplicates_element, which has [@@deriving bin_io] after its type definition. bin_prot functions do indeed get defined for this module, but I don’t understand how this module would help me serialize sequences, and none of the experiments I’ve tried with it have provided insight.

I don’t think that Merge_with_duplicates_element is by itself supposed to let me use Sequence with bin_prot. None of my experiments with it got anywhere.

We don’t do this internally because we don’t really use Sequence as a direct data-type for storing things, and so it hasn’t come up as a natural way to serialize data. Sequence obscures the concrete data type used to hold the data, so it rarely seems like the right thing to stick into a message.

That said, I think you should be able to do this using Binable.Of_binable1, where you use the serializer for lists or arrays to base the serializer for sequences.

Thanks @Yaron_Minsky. I’m willing to move the data to lists or arrays rather than directly serializing sequences. I thought I’d trying serializing sequences directly if that was available. I wasn’t actually sure what that would do–whether the generated data would be stored, or whether instead the generating function(s) would be serialized. I want the data, anyway. But I would like to end up with Sequence sequences after I unserialize it, since that’s what my code expects.

It sounds like jakemcarthur is now planning to add bin_io capabilities to Sequence, which would be convenient for me, but if not I can try the Binable.Of_binable1 route, or just copy data to lists or arrays. This wouldn’t be costly compared to generating the data, which takes a long time.