# \#list

**URL:** https://discuss.ocaml.org/tag/list/386.md

[Latest](https://discuss.ocaml.org/latest.md) · [Categories](https://discuss.ocaml.org/categories.md) · [Tags](https://discuss.ocaml.org/tags.md)

---

## [A tail-recursive List.flatten in Stdlib?](https://discuss.ocaml.org/t/a-tail-recursive-list-flatten-in-stdlib/15382)

<div class="topic-metadata">

**Author:** [@Chris1](https://discuss.ocaml.org/u/Chris1)\
**Replies:** 7\
**Last updated:** [October 6, 2024, 8:05pm UTC](https://discuss.ocaml.org/t/a-tail-recursive-list-flatten-in-stdlib/15382 "2024-10-06T20:05:05Z")

</div>

I was perusing the OCaml source code for Stdlib.List and noticed that List.flatten is implemented in a non-tail-recursive manner. let rec flatten = function \[\] -\> \[\] | l::r -\> l @ flatten r Is there a compellin…

---

## [Troubles using a simple functorised module for a list type](https://discuss.ocaml.org/t/troubles-using-a-simple-functorised-module-for-a-list-type/14835)

<div class="topic-metadata">

**Author:** [@chshersh](https://discuss.ocaml.org/u/chshersh)\
**Replies:** 5\
**Last updated:** [June 23, 2024, 12:54pm UTC](https://discuss.ocaml.org/t/troubles-using-a-simple-functorised-module-for-a-list-type/14835 "2024-06-23T12:54:22Z")

</div>

I’m playing with first-class modules in OCaml, and since I’m still a noob, I stumbled upon a compiler error I can’t resolve on my own. So I’d appreciate any help! :pray: I want to make a simple module for a semigroup li…

---

## [Bad use of optional arguments](https://discuss.ocaml.org/t/bad-use-of-optional-arguments/11889)

<div class="topic-metadata">

**Author:** [@carotte\_sauvage](https://discuss.ocaml.org/u/carotte_sauvage)\
**Replies:** 3\
**Last updated:** [April 6, 2023, 11:16am UTC](https://discuss.ocaml.org/t/bad-use-of-optional-arguments/11889 "2023-04-06T11:16:15Z")

</div>

Good evening, At this page « https://ocaml.org/problems#5 », the exercice asks to write the « rev » function, which reverses a list : let rev list = let rec aux acc = function | \[\] -\> acc | h :: t -\> aux (h :…

---

## [Adding indexed variants of all functions in stdlib](https://discuss.ocaml.org/t/adding-indexed-variants-of-all-functions-in-stdlib/12792)

<div class="topic-metadata">

**Author:** [@glen](https://discuss.ocaml.org/u/glen)\
**Replies:** 6\
**Last updated:** [August 11, 2023, 9:26am UTC](https://discuss.ocaml.org/t/adding-indexed-variants-of-all-functions-in-stdlib/12792 "2023-08-11T09:26:21Z")

</div>

I am thinking of adding index-aware variants of existing functions to the standard library. For instance, List.map has an indexed variant named List.mapi. Currently, only a minority of standard functions for which it wou…

---

## [Print a list of tuples](https://discuss.ocaml.org/t/print-a-list-of-tuples/12502)

<div class="topic-metadata">

**Author:** [@vivanov](https://discuss.ocaml.org/u/vivanov)\
**Replies:** 2\
**Last updated:** [June 29, 2023, 1:14pm UTC](https://discuss.ocaml.org/t/print-a-list-of-tuples/12502 "2023-06-29T13:14:22Z")

</div>

Hey, I am looking for a way to print structures for debugging purposes, and for other purposes. For example, I have a function that produces a list of tuples: List.mapi ( fun i (name, address) -\> Pri…

---

## [Weak type when partitioning a list](https://discuss.ocaml.org/t/weak-type-when-partitioning-a-list/12496)

<div class="topic-metadata">

**Author:** [@vivanov](https://discuss.ocaml.org/u/vivanov)\
**Replies:** 2\
**Last updated:** [June 28, 2023, 2:28pm UTC](https://discuss.ocaml.org/t/weak-type-when-partitioning-a-list/12496 "2023-06-28T14:28:44Z")

</div>

Hey, I am looking to get first n elements of a list: let rec first\_helper accum n l = match n, l with | 0, \_ -\> accum |\> List.rev | n, h :: t -\> first\_helper (h :: accum) (n - 1) t | \_, \_ -\> accum |\> List.…

---

## [Dump Hashtbl.t to list or assoc list](https://discuss.ocaml.org/t/dump-hashtbl-t-to-list-or-assoc-list/10389)

<div class="topic-metadata">

**Author:** [@olleharstedt](https://discuss.ocaml.org/u/olleharstedt)\
**Replies:** 2\
**Last updated:** [August 29, 2022, 9:33am UTC](https://discuss.ocaml.org/t/dump-hashtbl-t-to-list-or-assoc-list/10389 "2022-08-29T09:33:49Z")

</div>

Is there no easy or built-in way to dump all keys and/or values of a hash table to a list or assoc list? Lists are easier to use when asserting equality in tests, like test\_eq. I find iter, but no map, which is weird, o…

---

## [Angstrom number parser with GADT](https://discuss.ocaml.org/t/angstrom-number-parser-with-gadt/8563)

<div class="topic-metadata">

**Author:** [@cloudyhug](https://discuss.ocaml.org/u/cloudyhug)\
**Replies:** 1\
**Last updated:** [October 2, 2021, 7:43pm UTC](https://discuss.ocaml.org/t/angstrom-number-parser-with-gadt/8563 "2021-10-02T19:43:34Z")

</div>

Hello. I am building a parser for a number type with integral and rational values. type \_ number = I : int -\> int number | R : rat -\> rat number I have distinct functions to parse hexadecimal, binary, octal and decimal…

---

## [Pattern matching on a lazy list](https://discuss.ocaml.org/t/pattern-matching-on-a-lazy-list/6158)

<div class="topic-metadata">

**Author:** [@rwmjones](https://discuss.ocaml.org/u/rwmjones)\
**Replies:** 4\
**Last updated:** [July 30, 2020, 7:46am UTC](https://discuss.ocaml.org/t/pattern-matching-on-a-lazy-list/6158 "2020-07-30T07:46:26Z")

</div>

I’m trying to rewrite this Perl code in OCaml. The Perl code is horrible and very imperative. It strikes me it could be better if I could use OCaml and pattern matching. You can think of this code as something which “…
