# \#polymorphism

**URL:** https://discuss.ocaml.org/tag/polymorphism/258.md

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

---

## [Default argument to functors?](https://discuss.ocaml.org/t/default-argument-to-functors/18157)

<div class="topic-metadata">

**Author:** [@fnfun](https://discuss.ocaml.org/u/fnfun)\
**Replies:** 2\
**Last updated:** [May 22, 2026, 11:05am UTC](https://discuss.ocaml.org/t/default-argument-to-functors/18157 "2026-05-22T11:05:24Z")

</div>

I’m trying to create a functor with a sort of polymorphic default argument, but having no luck. Here’s the failed idea: First, a module with a pretty printer for a container element: module type PP = sig type t …

---

## [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…

---

## [Polymorphism in OCAML](https://discuss.ocaml.org/t/polymorphism-in-ocaml/14940)

<div class="topic-metadata">

**Author:** [@Smmn](https://discuss.ocaml.org/u/Smmn)\
**Replies:** 7\
**Last updated:** [July 12, 2024, 3:35pm UTC](https://discuss.ocaml.org/t/polymorphism-in-ocaml/14940 "2024-07-12T15:35:23Z")

</div>

Hi! I looked through multiple OCaml books, tried to search in the internet, gone through different example projects and tutorials and youtube videos… What is the way to do polymorphism in OCaml? I found many places on…

---

## [Explicitly polymorphic function inside a universally quantified record field (e.g., an effect handler)?](https://discuss.ocaml.org/t/explicitly-polymorphic-function-inside-a-universally-quantified-record-field-e-g-an-effect-handler/13889)

<div class="topic-metadata">

**Author:** [@Zeta](https://discuss.ocaml.org/u/Zeta)\
**Replies:** 6\
**Last updated:** [January 17, 2024, 2:58pm UTC](https://discuss.ocaml.org/t/explicitly-polymorphic-function-inside-a-universally-quantified-record-field-e-g-an-effect-handler/13889 "2024-01-17T14:58:04Z")

</div>

How do I define an explicitly polymorphic function inside a universally quantified record field, e.g., inside an effect handler? Here is a MWE: open Effect open Effect.Deep type \_ Effect.t += Eff : ('a -\> 'a) t let r…

---

## [Mapping GADT AST node to list of it's children not allowed by compiler?](https://discuss.ocaml.org/t/mapping-gadt-ast-node-to-list-of-its-children-not-allowed-by-compiler/10379)

<div class="topic-metadata">

**Author:** [@dan\_dan](https://discuss.ocaml.org/u/dan_dan)\
**Replies:** 3\
**Last updated:** [August 26, 2022, 9:24am UTC](https://discuss.ocaml.org/t/mapping-gadt-ast-node-to-list-of-its-children-not-allowed-by-compiler/10379 "2022-08-26T09:24:41Z")

</div>

I have a GADT type for representing an AST and would like to have a function that gives me a list of a nodes children wrapped in polyvariant let take\_next : type a. a t -\> \[\`Expr of expr t | \`Stmt of stmt t | \`Decl of d…

---

## [Polymorphic recursive classes](https://discuss.ocaml.org/t/polymorphic-recursive-classes/9607)

<div class="topic-metadata">

**Author:** [@mb64](https://discuss.ocaml.org/u/mb64)\
**Replies:** 3\
**Last updated:** [March 30, 2022, 8:09pm UTC](https://discuss.ocaml.org/t/polymorphic-recursive-classes/9607 "2022-03-30T20:09:12Z")

</div>

Is there a way to make a polymorphic recursive class? Here’s a simple example that does not compile: class \['a\] listy x = object method list = x method more\_lists : unit -\> 'a list listy = fun () -\> new…

---

## [GADT and polymorphic recursion](https://discuss.ocaml.org/t/gadt-and-polymorphic-recursion/9183)

<div class="topic-metadata">

**Author:** [@Kakadu](https://discuss.ocaml.org/u/Kakadu)\
**Replies:** 1\
**Last updated:** [January 19, 2022, 3:14pm UTC](https://discuss.ocaml.org/t/gadt-and-polymorphic-recursion/9183 "2022-01-19T15:14:29Z")

</div>

I’m writing some code about OCaml’s typedtree, my current result is too long and complex, and I want to make it better. Right now I have solutions that use 1) locally abstract types, and 2) non-prenex polymorphism via r…

---

## [Constraining type parameter to be polymorphic variant](https://discuss.ocaml.org/t/constraining-type-parameter-to-be-polymorphic-variant/7159)

<div class="topic-metadata">

**Author:** [@dgllghr](https://discuss.ocaml.org/u/dgllghr)\
**Replies:** 3\
**Last updated:** [January 25, 2021, 4:13pm UTC](https://discuss.ocaml.org/t/constraining-type-parameter-to-be-polymorphic-variant/7159 "2021-01-25T16:13:38Z")

</div>

I am writing a function that stores a key value pair asynchronously. The key is a string but the value is supplied as an async stream so that it can be streamed to the key-value store without loading the whole value into…

---

## [Problem with subtyping in polymorphic variant in gadt](https://discuss.ocaml.org/t/problem-with-subtyping-in-polymorphic-variant-in-gadt/6650)

<div class="topic-metadata">

**Author:** [@bn-d](https://discuss.ocaml.org/u/bn-d)\
**Replies:** 1\
**Last updated:** [October 24, 2020, 9:40am UTC](https://discuss.ocaml.org/t/problem-with-subtyping-in-polymorphic-variant-in-gadt/6650 "2020-10-24T09:40:36Z")

</div>

Hello, I was playing around with polymorphic variant in gadt. And I get some problem with subtyping. i.e I have type # type int\_ = \[ \`Int \];; # type real = \[ \`Int | \`Float \];; With list, I can do # let int\_list : int…

---

## [Functor implementing polymorphic module type... Help!](https://discuss.ocaml.org/t/functor-implementing-polymorphic-module-type-help/6382)

<div class="topic-metadata">

**Author:** [@gypsydave5](https://discuss.ocaml.org/u/gypsydave5)\
**Replies:** 11\
**Last updated:** [September 9, 2020, 10:10am UTC](https://discuss.ocaml.org/t/functor-implementing-polymorphic-module-type-help/6382 "2020-09-09T10:10:40Z")

</div>

OK, I’m asking this because it’s bugging me and distracting me from carrying on learning OCaml - so please help! Here’s the signature of a polymorphic set type - yes, there should be more functions defined but we’ll get…

---

## [Filtering constructors by type variable (GADTs + polymorphic variants)](https://discuss.ocaml.org/t/filtering-constructors-by-type-variable-gadts-polymorphic-variants/6195)

<div class="topic-metadata">

**Author:** [@tbrk](https://discuss.ocaml.org/u/tbrk)\
**Replies:** 6\
**Last updated:** [August 7, 2020, 12:06pm UTC](https://discuss.ocaml.org/t/filtering-constructors-by-type-variable-gadts-polymorphic-variants/6195 "2020-08-07T12:06:48Z")

</div>

The following problems arise in the context of a patch for adding support for bigarrays to the ocamlmpi library. I don’t know how to solve the third problem. I have a vague intuition that it is not possible, but I would …

---

## [Protocol buffers and parametric polymorphism](https://discuss.ocaml.org/t/protocol-buffers-and-parametric-polymorphism/6013)

<div class="topic-metadata">

**Author:** [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Replies:** 1\
**Last updated:** [June 23, 2020, 4:16am UTC](https://discuss.ocaml.org/t/protocol-buffers-and-parametric-polymorphism/6013 "2020-06-23T04:16:31Z")

</div>

Is there anybody here who would like to discuss parametric polymorphism and protocol buffers? I’ve had some musings, and while I think it would be “too much noise” to share them on this discussion forum (maybe I’m wrong…

---

## [How to cause functor types to "inherit" their elements' polymorphic variant subtyping relations](https://discuss.ocaml.org/t/how-to-cause-functor-types-to-inherit-their-elements-polymorphic-variant-subtyping-relations/3824)

<div class="topic-metadata">

**Author:** [@cemerick](https://discuss.ocaml.org/u/cemerick)\
**Replies:** 4\
**Last updated:** [May 24, 2019, 6:06pm UTC](https://discuss.ocaml.org/t/how-to-cause-functor-types-to-inherit-their-elements-polymorphic-variant-subtyping-relations/3824 "2019-05-24T18:06:36Z")

</div>

The following is a minimal example of the shape of what’s proven to be a very stubborn problem for me. Thanks in advance to everyone that takes the time to read this and maybe help get me unstuck. :slight\_smile: A link t…

---

## [Keeping polymorphism of universally quantified fields](https://discuss.ocaml.org/t/keeping-polymorphism-of-universally-quantified-fields/3570)

<div class="topic-metadata">

**Author:** [@Daiwen](https://discuss.ocaml.org/u/Daiwen)\
**Replies:** 4\
**Last updated:** [March 28, 2019, 8:19am UTC](https://discuss.ocaml.org/t/keeping-polymorphism-of-universally-quantified-fields/3570 "2019-03-28T08:19:09Z")

</div>

I have the following code snippet: type 'a f = 'a -\> 'a type foo = { f: 'a. 'a f } let seqF : 'a. 'a f -\> 'a f -\> 'a f = fun f1 f2 -\> fun a -\> let a = f1 a in f2 a let seq foo1 foo2 = { f = seqF foo1.f …

---

## [Arbitrary polymorphic variants as parameters](https://discuss.ocaml.org/t/arbitrary-polymorphic-variants-as-parameters/3560)

<div class="topic-metadata">

**Author:** [@VPhantom](https://discuss.ocaml.org/u/VPhantom)\
**Replies:** 4\
**Last updated:** [March 25, 2019, 1:57pm UTC](https://discuss.ocaml.org/t/arbitrary-polymorphic-variants-as-parameters/3560 "2019-03-25T13:57:25Z")

</div>

Hi fellow OCaml’ers! Long time reader, first time poster. :slight\_smile: I’m making a rookie mistake with polymorphic variants, but I can’t quite understand why. I figure others might stumble into this, so here goes… …

---

## [How to "merge" unknown tuples?](https://discuss.ocaml.org/t/how-to-merge-unknown-tuples/2444)

<div class="topic-metadata">

**Author:** [@egoholic](https://discuss.ocaml.org/u/egoholic)\
**Replies:** 6\
**Last updated:** [August 16, 2018, 6:42pm UTC](https://discuss.ocaml.org/t/how-to-merge-unknown-tuples/2444 "2018-08-16T18:42:39Z")

</div>

For relational programming I need an ability to join collections (relations) of tuples. Very simplified version of what I need looks like: Rel.join \[(1; "James")\] \[(1; 34)\] (\* returns: \[(1; "James"; 34)\] \*) How can I…
