# No cons function in Base.Sequence?

**URL:** <https://discuss.ocaml.org/t/no-cons-function-in-base-sequence/7406>\
**Category:** Learning\
**Created:** [March 3, 2021, 6:27pm UTC](https://discuss.ocaml.org/t/no-cons-function-in-base-sequence/7406 "2021-03-03T18:27:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://discuss.ocaml.org/u/Jonathan)\
**Post date:** [March 3, 2021, 6:27pm UTC](https://discuss.ocaml.org/t/no-cons-function-in-base-sequence/7406/1 "2021-03-03T18:27:17Z")

</div>

I have been looking at the [`Sequence`](https://ocaml.janestreet.com/ocaml-core/v0.14/doc/base/Base/Sequence/index.html#type-t) module in the Janestreet’s Base library and I was surprised to see that there is no `cons: 'a -> 'a t -> 'a t` function. In contrast, such a function is present in the [`Seq`](https://caml.inria.fr/pub/docs/manual-ocaml/libref/Seq.html) module of the standard library.

Is there a specific reason for omitting `cons` from `Sequence` (e.g. its abuse may lead to performance problems) or am I missing an alternative?

---

<div class="post-metadata">

**Author:** ![bcc32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bcc32/32/203_2.png) [@bcc32](https://discuss.ocaml.org/u/bcc32)\
**Post date:** [March 3, 2021, 6:48pm UTC](https://discuss.ocaml.org/t/no-cons-function-in-base-sequence/7406/2 "2021-03-03T18:48:43Z")

</div>

`Sequence.shift_right` is the function you are looking for.

See [here](https://ocaml.janestreet.com/ocaml-core/v0.14/doc/base/Base/Sequence/index.html#val-shift_right) for documentation. Also see `shift_right_with_list` for some explanation of the performance costs associated with `shift_right`.

---

<div class="post-metadata">

**Author:** ![cvine](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@cvine](https://discuss.ocaml.org/u/cvine)\
**Post date:** [March 3, 2021, 10:46pm UTC](https://discuss.ocaml.org/t/no-cons-function-in-base-sequence/7406/3 "2021-03-03T22:46:06Z")

</div>

I wonder if anyone has found much of a use for `Seq.cons`? In order to provide delayed (lazy) evaluation `'a Seq.t` is a thunk. But `Seq.cons` is a function and not a macro, so for an eager language such as ocaml its first argument is evaluated immediately, which seems somewhat to defeat the purpose.

Given a lazy sequence `s`, I think in most cases I would cons onto it by hand with `fun () -> Cons ([expr], s)`, so retaining lazy evaluation of `[expr]`. I guess `Seq.cons` is mostly used to prepend a literal value to a sequence?
