gren-lang / gren-lang/compiler

Monomorphize custom types

Open
#52 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Haskell
Stars
503
Forks
29
PR merge metrics
No merged PRs in 30d

Description

When the Gren compiler encounters a custom type like:

type Something
  = None
  | One Int
  | Two Int Int

It compiles it into (pseudo code)

var $namespace$None = { $: 'None' };

var $namespace$One = function(a) { return { $: 'One', a: a }; };

var $namespace$Two = function(a, b) { return { $: 'Two', a: a, b: b }; };

This means that the different constructors of Something return different types in the eyes of the JS JIT compiler. This again means that the performance of the code will be sub-optimal.

It would be better if the above Gren code produced something like:

var $namespace$Something = function(tag, a, b) {
  this.$ = tag;
  this.a = a;
  this.b = b;
};

var $namespace$None = new $namespace$Something('None', 0, 0);

var $namespace$One = function(a) { return new $namespace$Something('One', a, 0); };

var $namespace$Two = F2(function(a, b) { return new $namespace$Something('Two', a, b); });

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name specific files or tests. Start by locating the compiler entry point that generates JavaScript for custom types and inspect the constructor output for the shown Something example. Done means constructors share one representation while preserving the existing tags and fields, with relevant compiler tests passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.