flux icon indicating copy to clipboard operation
flux copied to clipboard

SPEC: Function Polymorphic Specialization

Open adamperlin opened this issue 7 years ago • 1 comments

From ifql created by jsternberg : influxdata/ifql#346

I think we should provide a way for function polymorphism by allowing a formal function declaration keyword. Something similar to how go uses func.

If we wanted to implement any kind of polymorphism, we might have difficulty in the current method.

special_filter = (table=<-, r) => table |> filter(fn: r)
special_filter = (table=<-, field) => table |> filter(fn: (r) => r._field == field)

In the above example, it looks like I am reassigning the special_filter variable to a new function and that would be disallowed because the types differ. But, if we want the ability to specify different parameters and behavior to a function, function overloading is the easiest way to deal with this rather than a never-ending set of keyword arguments that make it hard to determine what is what.

I think a simple syntax for function declarations would be helpful and allow us to specify multiple signatures for a single function name. I think it would also make it easier to create an auto-doc parser for functions.

func special_filter(table=<-, r) => table |> filter(fn: r)

Maybe something like that. While it would require func to be a keyword, I don't think that's a very big deal. Most people would use fn for an argument anyway.

The biggest issue I can think of would be specifying these function's types, but I would also like to introduce static typing into the language. So this is more a proposal.

adamperlin avatar Jul 03 '18 20:07 adamperlin

Flux currently does have polymorphic functions, but it does not have the ability to specialize the implementation of the function.

nathanielc avatar Jul 03 '19 19:07 nathanielc

This issue has had no recent activity and will be closed soon.

github-actions[bot] avatar Nov 30 '24 01:11 github-actions[bot]