# JavaScript implementation of Julia's dispatch rules

**URL:** <https://discourse.julialang.org/t/javascript-implementation-of-julias-dispatch-rules/120979>\
**Category:** Tooling\
**Created:** [October 6, 2024, 4:29pm UTC](https://discourse.julialang.org/t/javascript-implementation-of-julias-dispatch-rules/120979 "2024-10-06T16:29:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 6, 2024, 4:29pm UTC](https://discourse.julialang.org/t/javascript-implementation-of-julias-dispatch-rules/120979/1 "2024-10-06T16:29:31Z")

</div>

I’ve thought for a while that it would be neat to have interactive javascript components for docs pages where you can select the methods you’re interested in for a given function. I’m thinking of some kind of multiple-dropdowns widget that determines which methods match given some input types a user selects. But it should not call out to Julia given it would need to run on docs pages without a Julia server backing it. So some (reduced) type tree needs to be stored as well as all the signatures of functions one cares about.

When I last looked into it, I quickly found though that I wasn’t sure how to write down Julia’s dispatch algorithm. Especially where it gets more complicated with ambiguity, unionalls, etc. Does anyone know of an accessible source somewhere that explains how that algorithm works exactly, such that one can recreate it one-to-one in Javascript?

---

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [October 6, 2024, 10:24pm UTC](https://discourse.julialang.org/t/javascript-implementation-of-julias-dispatch-rules/120979/2 "2024-10-06T22:24:23Z")

</div>

Probably a silly question, but is dispatch implemented in C? If so, could it be compiled to WASM?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 7, 2024, 7:58am UTC](https://discourse.julialang.org/t/javascript-implementation-of-julias-dispatch-rules/120979/3 "2024-10-07T07:58:11Z")

</div>

Maybe, but I guess it’s tied into a lot of Julia internals that I wouldn’t want to mirror over to the JavaScript side. Types have a lot of fields that aren’t really necessary for the base functionality, I think.

---

<div class="post-metadata">

**Author:** ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)\
**Post date:** [October 7, 2024, 9:44pm UTC](https://discourse.julialang.org/t/javascript-implementation-of-julias-dispatch-rules/120979/4 "2024-10-07T21:44:08Z")

</div>

A good starting point (and maybe your best bet at the moment) is this [paper](https://julbinb.github.io/projects/lambda-julia) on subtyping in Julia. The link to the main project page also includes a reference implementation.

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [October 7, 2024, 9:47pm UTC](https://discourse.julialang.org/t/javascript-implementation-of-julias-dispatch-rules/120979/5 "2024-10-07T21:47:48Z")

</div>

> [@bertschi](#):
>
> A good starting point (and maybe your best bet at the moment) is this [paper](https://julbinb.github.io/projects/lambda-julia) on subtyping in Julia.

I’m not sure that paper or implementation is still useful for such a purpose, because it’s outdated.

> [@jules](#):
>
> how that algorithm works exactly

AFAIK this is defined by the reference implementation, and certainly changes from time to time. Such as that time when a discussion here lead to bug fixes in the subtyping.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 8, 2024, 7:23am UTC](https://discourse.julialang.org/t/javascript-implementation-of-julias-dispatch-rules/120979/7 "2024-10-08T07:23:12Z")

</div>

I’ll have a look at that paper. Even if it doesn’t 100% match the reference implementation I guess those edge cases are less important for a UI prototype that I’m not even sure will work at all
