google-research / google-research/dex-lang

Rethink overloading

Open
#671 12 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

language / concrete syntax language / type system
Dominant language
Haskell
Stars
1.7k
Forks
117
PR merge metrics
No merged PRs in 30d

Description

As Julia demonstrates, ad hoc overloading is a great fit for numerical computing! In Dex we have some support for it, in the form of interfaces (type classes), but I would claim that it's still a little less ad'hoc then we would like (in the spirit opposite to How to make ad-hoc polymorphism less ad hoc that introduced type classes). In particular, when defining a type class one has to pick a single type signature that would then be enforced on every single implementation. The big benefit of this approach is that it plays very well with parametric polymorphism and type inference, but it does limit expressivity. For example, when defining interface Mul a it is tempting to just say

(*) : a -> a -> a

but that means that no one will ever be able to overload * to represent the common Python idiom of "a" * 4.

I'm not sure what the options are, but we should do something about it. Julia's standard library features over 20 types for matrices and it would be a shame to miss out on this. One potential solution would be to add support for type-directed name resolution (which is already supported in Idris). It doesn't play quite as well with polymorphic functions, but it does work well in monomorphic environments like at the top level.

(cc @oxinabox for any insights)

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

No source files, tests, or entry points are named. Start by reading the issue's discussion of Dex interfaces, Julia's overloading model, and the linked material on type-directed name resolution. Done would require an agreed approach for more expressive overloading, but the issue does not define a concrete implementation scope or acceptance test.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, julia
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
18/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.