# Bin\_io/bin\_prot with Core.Sequence?

**URL:** <https://discuss.ocaml.org/t/bin-io-bin-prot-with-core-sequence/2129>\
**Category:** Learning\
**Tags:** core, bin\_prot\
**Created:** [June 12, 2018, 5:26am UTC](https://discuss.ocaml.org/t/bin-io-bin-prot-with-core-sequence/2129 "2018-06-12T05:26:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [June 12, 2018, 5:26am UTC](https://discuss.ocaml.org/t/bin-io-bin-prot-with-core-sequence/2129/1 "2018-06-12T05:26:35Z")

</div>

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:

```ocaml
# 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 `sequence.ml` 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.

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [June 18, 2018, 1:15pm UTC](https://discuss.ocaml.org/t/bin-io-bin-prot-with-core-sequence/2129/2 "2018-06-18T13:15:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [June 18, 2018, 7:30pm UTC](https://discuss.ocaml.org/t/bin-io-bin-prot-with-core-sequence/2129/3 "2018-06-18T19:30:49Z")

</div>

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.
