Function Parameter Speculation #17168

First off, thanks for the awesome work on static analysis and AOT compiled Julia! Looks like you’re working on the three language problem–expressiveness of python, speed of C, and static analysis / safety of Haskell. :grin:

In pure math there is no concept of a dynamic value. Because Haskell is a pure functional language that uses Hindley–Milner type inference, there is no need for dynamic dispatch as there are no dynamic values.[1] In the Haskell world-view, dynamic values come from outside world–reading a file, user input, streaming data, a random number, etc.–hence the IO monad to bind dynamic values to static values. Following an IO, static multiple dispatch can take place. Note that IO has nothing to do with dispatching per se, just one of many uses. This purity makes computations involving random numbers surprisingly involved and has a number of other undesirable tradeoffs for scientific computing.

Thanks for diving into Rust. Makes sense that its implementation is too restricted for Julia.

I love the idea of Interfaces. They also require functions to have types. I’m strongly in support of first-class function types in Julia for reasons described on the Github thread. Given that dynamic multiple dispatch seems to be a foundational idea of Julia, I assume this doesn’t change and ask the following questions:

  1. What is the type of a method?
  2. What is the type of a function?
  3. How do the types of methods and functions relate?
  4. How do multiple dispatch, traits, interfaces, and types all relate?
  5. Are the answers we come up with implementable and generally compatible with idiomatic Julia code?

Some observations:

  1. Given that methods are associate with argument types, so should the method’s type. I hold as self-evident that the return type should be included too. So following StefanKarpinski’s lead this is f :: A → B in Julia

  2. This is a hard question. It seems related to type classes, traits and/or interfaces. Alternatively, when viewed as a “type of types,” that suggests this is a kind e.g. * in Haskell or Any in Julia.

  3. Methods have a dependency relationship on Function

  4. Strategically, we should look for a common abstraction. Haskell provides a nice example of how type classes give us all of these.

  5. I’ll defer this one!

[1] this is not strictly true as there is a type Dynamic, but this is hardly used and not idiomatic. So it turns out there is in fact dynamic multiple dispatch in Haskell.

1 Like