# \#objects

**URL:** https://discuss.ocaml.org/tag/objects/245.md

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

---

## [Unifying inferred type of method with optional parameter?](https://discuss.ocaml.org/t/unifying-inferred-type-of-method-with-optional-parameter/17636)

<div class="topic-metadata">

**Author:** [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Replies:** 1\
**Last updated:** [December 25, 2025, 9:51am UTC](https://discuss.ocaml.org/t/unifying-inferred-type-of-method-with-optional-parameter/17636 "2025-12-25T09:51:08Z")

</div>

I ran into this issue: # let test cond o = if cond then o#f ~x:1 2 else o#f 2;; Error: This function is applied to arguments in an order different from other calls. This is only allowed when the r…

---

## [Returning an object with additional fields](https://discuss.ocaml.org/t/returning-an-object-with-additional-fields/15348)

<div class="topic-metadata">

**Author:** [@s.t.s](https://discuss.ocaml.org/u/s.t.s)\
**Replies:** 43\
**Last updated:** [October 7, 2024, 3:18pm UTC](https://discuss.ocaml.org/t/returning-an-object-with-additional-fields/15348 "2024-10-07T15:18:50Z")

</div>

I’m trying to implement an approach, where several related record types are inserted into a data structure. Since the record types are related, I am using classes and inheritance to form the desired set of fields. The …

---

## [Actual Performance Costs of OOP Objects](https://discuss.ocaml.org/t/actual-performance-costs-of-oop-objects/9400)

<div class="topic-metadata">

**Author:** [@bluddy](https://discuss.ocaml.org/u/bluddy)\
**Replies:** 56\
**Last updated:** [October 3, 2024, 10:11am UTC](https://discuss.ocaml.org/t/actual-performance-costs-of-oop-objects/9400 "2024-10-03T10:11:23Z")

</div>

I’d like to understand what the actual performance implications are of OCaml objects. Everyone likes to denigrate them, but what are their performance characteristics really like (and why)?

---

## [Does using object types in GADTs get you any more power?](https://discuss.ocaml.org/t/does-using-object-types-in-gadts-get-you-any-more-power/14042)

<div class="topic-metadata">

**Author:** [@Joel](https://discuss.ocaml.org/u/Joel)\
**Replies:** 10\
**Last updated:** [September 16, 2024, 2:41pm UTC](https://discuss.ocaml.org/t/does-using-object-types-in-gadts-get-you-any-more-power/14042 "2024-09-16T14:41:32Z")

</div>

I recently learned that you could use object types in GADTs! In this example it’s just used as a “type-level record”, which if I understand correctly means that it isn’t much more powerful that using \* or -\> types, with …

---

## [In defense of OCaml objects](https://discuss.ocaml.org/t/in-defense-of-ocaml-objects/14215)

<div class="topic-metadata">

**Author:** [@toots](https://discuss.ocaml.org/u/toots)\
**Replies:** 4\
**Last updated:** [February 29, 2024, 6:51pm UTC](https://discuss.ocaml.org/t/in-defense-of-ocaml-objects/14215 "2024-02-29T18:51:17Z")

</div>

The case for objects in OCaml: duck typed values Personally, I really dislike the object paradigm in programming and believe it’s bound to disappear. It’s an over-engineered paradigm that was introduced in a very early …

---

## [\`self\` use case?](https://discuss.ocaml.org/t/self-use-case/11774)

<div class="topic-metadata">

**Author:** [@anzhi0708](https://discuss.ocaml.org/u/anzhi0708)\
**Replies:** 4\
**Last updated:** [March 24, 2023, 2:37pm UTC](https://discuss.ocaml.org/t/self-use-case/11774 "2023-03-24T14:37:12Z")

</div>

Hello! Documentation says ...In fact this names the object, allowing you to call methods in the same class or pass the object to functions outside the class. In other words, it's exactly the same as this in C++/Java. ..…

---

## [Crazy OCaml dynamic evaluation: is this legal (defined behaviour)?](https://discuss.ocaml.org/t/crazy-ocaml-dynamic-evaluation-is-this-legal-defined-behaviour/10261)

<div class="topic-metadata">

**Author:** [@Gopiandcode](https://discuss.ocaml.org/u/Gopiandcode)\
**Replies:** 10\
**Last updated:** [October 21, 2022, 6:32am UTC](https://discuss.ocaml.org/t/crazy-ocaml-dynamic-evaluation-is-this-legal-defined-behaviour/10261 "2022-10-21T06:32:31Z")

</div>

Note: this is part of some code I’m writing for a research project, so don’t worry about such insanity somehow floating into actual production code :wink: . I’ve been recently working on a project wherein, for various r…

---

## [Type of parameterized class is not bound within methods](https://discuss.ocaml.org/t/type-of-parameterized-class-is-not-bound-within-methods/9618)

<div class="topic-metadata">

**Author:** [@stw](https://discuss.ocaml.org/u/stw)\
**Replies:** 4\
**Last updated:** [April 3, 2022, 8:45pm UTC](https://discuss.ocaml.org/t/type-of-parameterized-class-is-not-bound-within-methods/9618 "2022-04-03T20:45:02Z")

</div>

Defining a local exception or module using the type of the parameterized class is not possible as the type is not bound. See this minimal example: class \['a\] foo = object method bar : unit = (\* Neither of th…

---

## [Convert Yojson to object?](https://discuss.ocaml.org/t/convert-yojson-to-object/9226)

<div class="topic-metadata">

**Author:** [@Paul\_A\_Steckler](https://discuss.ocaml.org/u/Paul_A_Steckler)\
**Replies:** 21\
**Last updated:** [January 29, 2022, 3:33am UTC](https://discuss.ocaml.org/t/convert-yojson-to-object/9226 "2022-01-29T03:33:34Z")

</div>

Is there a way to convert a Yojson Assoc to an OCaml object, whose methods correspond to the Assoc items, and do so recursively, so that if an item contains another Assoc, you get an object for that?

---

## [Help with type trickery for implementing an Entity Component System framework](https://discuss.ocaml.org/t/help-with-type-trickery-for-implementing-an-entity-component-system-framework/8062)

<div class="topic-metadata">

**Author:** [@roddy](https://discuss.ocaml.org/u/roddy)\
**Replies:** 6\
**Last updated:** [June 30, 2021, 5:04pm UTC](https://discuss.ocaml.org/t/help-with-type-trickery-for-implementing-an-entity-component-system-framework/8062 "2021-06-30T17:04:48Z")

</div>

I’m trying to write a type-safe Entity Component System in OCaml. The idea is that an entity is has values for a set of components, and type of an entity is parameterised by the components it has so that it is only well-…

---

## [Objects use cases in OCaml](https://discuss.ocaml.org/t/objects-use-cases-in-ocaml/2282)

<div class="topic-metadata">

**Author:** [@egoholic](https://discuss.ocaml.org/u/egoholic)\
**Replies:** 38\
**Last updated:** [June 19, 2019, 6:43am UTC](https://discuss.ocaml.org/t/objects-use-cases-in-ocaml/2282 "2019-06-19T06:43:17Z")

</div>

Typical OCaml developer prefers not to use OO-features, but sometimes choosing objects over other composable “granules” is the simplest solution. Could you please share your own experience when objects is a MUST or a bes…

---

## [How to model a GUI view hierarchy using classes/objects](https://discuss.ocaml.org/t/how-to-model-a-gui-view-hierarchy-using-classes-objects/3899)

<div class="topic-metadata">

**Author:** [@borisd](https://discuss.ocaml.org/u/borisd)\
**Replies:** 3\
**Last updated:** [June 7, 2019, 7:07am UTC](https://discuss.ocaml.org/t/how-to-model-a-gui-view-hierarchy-using-classes-objects/3899 "2019-06-07T07:07:57Z")

</div>

Here’s a simplified version of the problem I’m facing: class view = object (\_ : 'a) method addSubview (\_v : 'a) = () end class button = object inherit view method setTitle (\_title : string) = …

---

## [Defining several similar classes by inheritance](https://discuss.ocaml.org/t/defining-several-similar-classes-by-inheritance/3717)

<div class="topic-metadata">

**Author:** [@thierry-martinez](https://discuss.ocaml.org/u/thierry-martinez)\
**Replies:** 5\
**Last updated:** [May 22, 2019, 1:53pm UTC](https://discuss.ocaml.org/t/defining-several-similar-classes-by-inheritance/3717 "2019-05-22T13:53:55Z")

</div>

Dear OCaml community, Let say I have two classes a and b that define methods a#m and b#m (we can suppose that these methods overload the method O#m from a common ancestor o of the classes a and b if it helps). I can de…
