Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCaml "list" with constant append to front and back?

Tags:

ocaml

I am new to OCaml, and curious if there is a (standardish) data structure in OCaml equivalent to

http://hackage.haskell.org/package/containers-0.2.0.1/docs/Data-Sequence.html

which provides O(1) prepend and append operations?

like image 984
Jonathan Gallagher Avatar asked Mar 16 '23 08:03

Jonathan Gallagher


1 Answers

I believe this is commonly called a deque.

Here's an implementation in OCaml Batteries Included:

http://ocaml-batteries-team.github.io/batteries-included/hdoc/BatDeque.html

This looks like something similar in Jane Street Core:

https://ocaml.janestreet.com/ocaml-core/111.17.00/doc/core/#Dequeue

These are (I would claim) the two most widely used basic OCaml libraries.

like image 160
Jeffrey Scofield Avatar answered Mar 19 '23 06:03

Jeffrey Scofield