# \#variant

**URL:** https://discuss.ocaml.org/tag/variant/737.md

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

---

## [Matching on variants (beginner question!)](https://discuss.ocaml.org/t/matching-on-variants-beginner-question/18083)

<div class="topic-metadata">

**Author:** [@Deverapaza](https://discuss.ocaml.org/u/Deverapaza)\
**Replies:** 2\
**Last updated:** [May 11, 2026, 10:02am UTC](https://discuss.ocaml.org/t/matching-on-variants-beginner-question/18083 "2026-05-11T10:02:00Z")

</div>

Taking first steps in Ocaml (have some background in Python, Rust, Clojure, etc) but already stumbling on the first hurdle… When playing around with variants and matching in utop and trying this code: type rgb\_color = …

---

## [Variant mapping to string and back](https://discuss.ocaml.org/t/variant-mapping-to-string-and-back/17813)

<div class="topic-metadata">

**Author:** [@vivanov](https://discuss.ocaml.org/u/vivanov)\
**Replies:** 3\
**Last updated:** [February 16, 2026, 4:16pm UTC](https://discuss.ocaml.org/t/variant-mapping-to-string-and-back/17813 "2026-02-16T16:16:09Z")

</div>

Hey, suppose I have a variant type type basic\_color = | Black | Red | Green | Yellow | Blue | Magenta | Cyan | White let to\_string = function | Black -\> "1" | Red -\> "2" | Green -\> "3" | Yellow…
