Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

How do we implement Ratio and Complex? #50

Closed
stylewarning opened this issue Sep 2, 2021 · 5 comments
Closed

How do we implement Ratio and Complex? #50

stylewarning opened this issue Sep 2, 2021 · 5 comments

Comments

@stylewarning
Copy link
Member

stylewarning commented Sep 2, 2021

There is difficulty in implementing these as native Lisp objects, because:

  • Problem 1: reduction of #C(k 0) to k; or k/1 to k

  • Problem 2: Lisp doesn't allow arbitrary field elements as components (Complex :a cannot use Lisp's complex numbers)

How do we implement Complex Single-Float as specialized on (COMPLEX SINGLE-FLOAT), but also allow Num :a => Complex :a to exist?

@stylewarning
Copy link
Member Author

See also lisp-type

@bitmappergit
Copy link

bitmappergit commented Sep 3, 2021

I don't think Ratio is an issue once #51 is solved due to the reduction of those to integers being the first thing that happens, which would then have something like ((Num :a) => :a) for their type, and ratios must have an instance of Num to implement Fractional.

@eliaslfox
Copy link
Collaborator

I think @stylewarning is referring to the fact that SBCL will convert #C(k 0) into a real type at runtime.

@stylewarning
Copy link
Member Author

Yes:

CL-USER> 4/3
4/3
CL-USER> (type-of *)
RATIO
CL-USER> 4/2
2
CL-USER> (type-of *)
(INTEGER 0 4611686018427387903)
CL-USER> #C(2 1)
#C(2 1)
CL-USER> (type-of *)
(COMPLEX (INTEGER 1 2))
CL-USER> #C(2 0)
2
CL-USER> (type-of *)
(INTEGER 0 4611686018427387903)

@bitmappergit
Copy link

Ah, sorry, I misunderstood the issue.

It might just be best to represent these as a datatype like in Haskell, and handle this in the codegen?

@coalton-lang coalton-lang locked and limited conversation to collaborators Sep 13, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

4 participants