# \#pattern

**URL:** https://discuss.ocaml.org/tag/pattern/450.md

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

---

## [Fragile pattern-matching not detected](https://discuss.ocaml.org/t/fragile-pattern-matching-not-detected/17645)

<div class="topic-metadata">

**Author:** [@user1](https://discuss.ocaml.org/u/user1)\
**Replies:** 4\
**Last updated:** [December 29, 2025, 12:08am UTC](https://discuss.ocaml.org/t/fragile-pattern-matching-not-detected/17645 "2025-12-29T00:08:46Z")

</div>

I began using the compiler flag that triggers the warning Warning 4 \[fragile-match\]: this pattern-matching is fragile. It will remain exhaustive when constructors are added to type t. because I feel safer with it. But …

---

## [How can you "un-functorize" an API to make it polymorphic while retaining type safety and efficiency?](https://discuss.ocaml.org/t/how-can-you-un-functorize-an-api-to-make-it-polymorphic-while-retaining-type-safety-and-efficiency/16005)

<div class="topic-metadata">

**Author:** [@bsidhom](https://discuss.ocaml.org/u/bsidhom)\
**Replies:** 10\
**Last updated:** [January 23, 2025, 4:31pm UTC](https://discuss.ocaml.org/t/how-can-you-un-functorize-an-api-to-make-it-polymorphic-while-retaining-type-safety-and-efficiency/16005 "2025-01-23T16:31:43Z")

</div>

As a learning exercise while studying 2-3 finger trees, I’ve implemented the data structure in a handful of different languages. It turns out that the OCaml version is (thus far) the most readable while still retaining a…

---

## [Wildcards in pattern-matching / recursive function](https://discuss.ocaml.org/t/wildcards-in-pattern-matching-recursive-function/13530)

<div class="topic-metadata">

**Author:** [@hmackiernan](https://discuss.ocaml.org/u/hmackiernan)\
**Replies:** 2\
**Last updated:** [November 30, 2023, 7:52pm UTC](https://discuss.ocaml.org/t/wildcards-in-pattern-matching-recursive-function/13530 "2023-11-30T19:52:31Z")

</div>

The tutorial I’m following has the following example code for a recursive function that uses pattern matching to return the length of a list # let rec length u = match u with | \[\] -\> 0 | \_ :: v -\> 1 + length…

---

## [\[help\] Regex pattern and raw strings](https://discuss.ocaml.org/t/help-regex-pattern-and-raw-strings/11747)

<div class="topic-metadata">

**Author:** [@anzhi0708](https://discuss.ocaml.org/u/anzhi0708)\
**Replies:** 2\
**Last updated:** [March 22, 2023, 7:44pm UTC](https://discuss.ocaml.org/t/help-regex-pattern-and-raw-strings/11747 "2023-03-22T19:44:50Z")

</div>

Hello folks! Another day, another noob question. Help wanted :3 I wrote this function to remove every ‘\\n’ in the string. let remove\_newlines (str : string) : string = Str.global\_replace (Str.regexp "\\n") "" str B…

---

## [Constant string pattern matching](https://discuss.ocaml.org/t/constant-string-pattern-matching/10801)

<div class="topic-metadata">

**Author:** [@nobrowser](https://discuss.ocaml.org/u/nobrowser)\
**Replies:** 6\
**Last updated:** [November 16, 2022, 6:01pm UTC](https://discuss.ocaml.org/t/constant-string-pattern-matching/10801 "2022-11-16T18:01:01Z")

</div>

Let’s say I write something like this: match lexeme with | "foo00" -\> Foo00 | "foo01" -\> Foo01 ... | "foo50" -\> Foo50 | \_ -\> FooError (My real keywords are not uniform like this.) Does this compile to the obvious st…

---

## [How to enforce valid db IDs with phantom types?](https://discuss.ocaml.org/t/how-to-enforce-valid-db-ids-with-phantom-types/10705)

<div class="topic-metadata">

**Author:** [@Danielo\_Rodriguez](https://discuss.ocaml.org/u/Danielo_Rodriguez)\
**Replies:** 16\
**Last updated:** [November 3, 2022, 10:54am UTC](https://discuss.ocaml.org/t/how-to-enforce-valid-db-ids-with-phantom-types/10705 "2022-11-03T10:54:54Z")

</div>

I have been using phantom types for some time now, and it’s been a fantastic experience. My main use case is to create correct types that only my modules know how to deal with and enforce consistency and correctness. How…

---

## [Locally Abstract Types in an Or-pattern with a GADT Scrutinee: Clash during Refinement?](https://discuss.ocaml.org/t/locally-abstract-types-in-an-or-pattern-with-a-gadt-scrutinee-clash-during-refinement/9315)

<div class="topic-metadata">

**Author:** [@YueLiPicasso](https://discuss.ocaml.org/u/YueLiPicasso)\
**Replies:** 5\
**Last updated:** [February 14, 2022, 6:06pm UTC](https://discuss.ocaml.org/t/locally-abstract-types-in-an-or-pattern-with-a-gadt-scrutinee-clash-during-refinement/9315 "2022-02-14T18:06:55Z")

</div>

Patterning matching with or-pattern, locally abstract types and GADT has some curious semantics. Consider the code below , which is a standard implementation of type witness and equality witness, with an additional prob…

---

## [Share your crazy OCaml code snippet!](https://discuss.ocaml.org/t/share-your-crazy-ocaml-code-snippet/8116)

<div class="topic-metadata">

**Author:** [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Replies:** 44\
**Last updated:** [November 30, 2021, 2:43pm UTC](https://discuss.ocaml.org/t/share-your-crazy-ocaml-code-snippet/8116 "2021-11-30T14:43:53Z")

</div>

Do you have some particularly beautiful, fun or strange or interesting OCaml piece of code that you want to share? If so, just tell us a bit about what this code is doing and why you find it so interesting/fun/strange/…
