Skip to content

Conversation

Madhav2310
Copy link
Contributor

No description provided.


@overload
def Decimal(x: i64) -> i64:
return x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>> from decimal import *
>>> Decimal(1)
Decimal('1')
>>> type(Decimal(1))
<class 'decimal.Decimal'>

Let's start off with something like the following,

@dataclass
class Decimal:
    value: str

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove @dataclass from Decimal in future. For now using them should be okay.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @certik

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just implement these the right way, that is, they have to be implemented as a class, that implements some methods that you can then call. So we have to first implement classes in LPython.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it have overloading too? Something like:

@dataclass
class Decimal:

    @overload
    def Decimal(x: i64) -> i64:
        return x
    @overload
    def Decimal(x: i32) -> i32:
        return x

    @overload
    def Decimal(x: f32) -> f64:
        return float(x)
    @overload
    def Decimal(x: f64) -> f64:
        return float(x)
    

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please explain why I am facing this particular error, what should be necessarily done differently?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can support overloading of methods, but as a second iteration, not first (it might be a bit involved, but doable).

Why don't you open up an issue for what is needed. I think what is needed is support for this:

class Decimal:
    def f(x: i64) -> i64:
        return x

def g() -> Decimal:
    return Decimal()

x: Decimal = g()
print(x.f())

And probably more, but the above is a start. Can you please open up an issue for this? Then let's implement it in LPython. Then you'll abe able to use it, and we can then open up issues for any missing features, etc.

@Madhav2310 Madhav2310 changed the title decimal module inititiated decimal module initiated Jul 1, 2022
@Madhav2310
Copy link
Contributor Author

@czgdp1807 please see if this is good for merging, and how can we improve it

@Madhav2310 Madhav2310 requested a review from czgdp1807 July 15, 2022 21:08
@czgdp1807 czgdp1807 added the could close Issues/PRs which can be closed. label Oct 5, 2022
@certik
Copy link
Contributor

certik commented Oct 5, 2022

@czgdp1807 can you please review this PR? It looks like @Madhav2310 asked you to review it, but somehow we missed it.

@czgdp1807
Copy link
Collaborator

This requires full class support (especially method calling, object reaction). Data classes alone won't be sufficient to implement this. I discussed this with @Madhav2310 in one of the GSoC weekly meetings and we arrived at the same conclusion.

@Smit-create Smit-create marked this pull request as draft November 9, 2022 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
could close Issues/PRs which can be closed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants