Skip to content

Add object method components #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Josef-Thorne-A
Copy link

@Josef-Thorne-A Josef-Thorne-A commented Mar 11, 2025

This is a draft PR for adding a syntax for object-based custom tags in MLX.

I will note that I was unable to figure out how to get ocamlmerlin_mlx to work with this as I don't have a good understanding of how MLX is extending merlin and where the changes would need to be made -- if I could be pointed in the right direction I will be happy to make those changes myself. The syntax itself is working. Some of my changes to the parser could probably be streamlined too by someone more knowledgeable in Menhir.

The syntax

<obj#view> children </obj#view>
<obj#view />
<obj# />
where obj is an Ocaml object with the method view. The method can have any name or, if not specified and only the hash is added, the method make will be inferred.

Why do this?

Objects are a part of the Ocaml ecosystem. While they are sometimes maligned, they have many legitimate use cases -- open recursion being the key example. In the wider programming world, objects are widely considered good fit for GUI building. I personally have found the lack of object components to be a major pain point in my project. While some of their use cases can be subsumed by first class modules -- these tend to be syntactically heavy and don't provide a good alternative when the problem at hand is best solved by open recursion or inheritance.

Object-based components let users of MLX take advantage of objects without having to use heavy syntax or packing object methods into an identifier. There seem to be no clear disadvantages to adding this feature -- most OCamler's are pretty averse to objects too so I don't think they're likely to go crazy with them and get themselves in trouble.

@davesnx davesnx requested a review from andreypopp March 17, 2025 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant