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

Add Data.Complex instances #1091

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TravisWhitaker
Copy link

There are loads of utility functions for defining the included instances. I guessed at which ones should be used for Data.Complex, but if I guessed incorrectly please say so.

I used a two-element array as the representation because that's how I've seen APIs in the wild do it, but perhaps {i : ..., q : ...} or {real : ..., imag : ...} would be preferred?

@TravisWhitaker
Copy link
Author

@phadej any thoughts on this?

@phadej
Copy link
Collaborator

phadej commented Nov 11, 2024

I'd pick {real : ..., imag : ...}, it will be analogous to Ratio. Also add FromJSON1 and ToJSON1 instance. Ratio doesn't have those, as it has an invariant, but Complex is really just a homogeneous pair (yet the common use case as number could be confusing when encoding as just a pair).

EDIT: I made a quick google, and it doesn't seem that there is an agreement to how encode complex numbers in JSON, so having more self-explanatory encoding is better.

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

Successfully merging this pull request may close these issues.

2 participants