Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic literals #3348

Closed
jpacik opened this issue Nov 21, 2020 · 3 comments
Closed

Polymorphic literals #3348

jpacik opened this issue Nov 21, 2020 · 3 comments

Comments

@jpacik
Copy link
Contributor

jpacik commented Nov 21, 2020

This epic will be complete when we can use integer literals in different contexts in a type safe way across flux. For example

a = 1
b = a + 1
c = a + 1.1

Polymorphic literals must also be supported in lambda functions. The following query should work regardless of whether r._value is a float or an int

|> map(fn: (r) => ({_value: r._value + 1}))
@jpacik jpacik added this to the Sprint 20-Q4-4 milestone Nov 21, 2020
@nathanielc nathanielc removed this from the Sprint 21-Q1-1 milestone Jan 25, 2021
@nathanielc
Copy link
Contributor

Related child issues #3347 #3337 #476 #3389

@Marwes
Copy link
Contributor

Marwes commented Oct 8, 2021

There seems to be two PRs to attempt to implemented this (#3360 and #3252) however I would argue that how they work at the interpreter level is flawed, or at least incomplete. Their implementation avoids converting the literal to the actual type at creation and just keeps it as an integer value. Operators like +: float -> float -> float are then overloaded with functions that also accept integers in their place to handle the values created by these literals. This is very error prone as forgetting to include some combination will result in a runtime panic but even with all operators covered you will also have to deal with these integers in functions defined in go etc.

To make this sane I think the interpreter needs a single, generic number type (ala python) or we do it the statically typed way and implement monomorphization, or dictionary passing so that we know how to convert the integer literal at its creation.

(One way to think of this is that the current implementation of constraints cheat a bit by utilizing the dynamic type in the interpreter to choose which implementation of + etc to call. This only supports generic functions where the type is known in the argument of the function + : a -> a -> a, but falls apart when only the output knowns fromInteger : Int -> a)

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants