Skip to content

Record instances #207

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

Closed
kl0tl opened this issue Feb 8, 2020 · 4 comments
Closed

Record instances #207

kl0tl opened this issue Feb 8, 2020 · 4 comments

Comments

@kl0tl
Copy link
Member

kl0tl commented Feb 8, 2020

Are Semigroup, Monoid, Semiring and Ring instances for records using Record.Unsafe.unsafeSet on purpose instead of composing a bunch of record builders? Don’t that yield a lot more garbage?

Also is there a reason for not having records instances of Bounded, EuclideanRing and DivisionRing?

@natefaubion
Copy link

Not necessarily more garbage since builders will allocate closures (as opposed to new records). I think it's mainly that prelude doesn't depend on any other libraries, and Builder is part of purescript-record.

@hdgarrood
Copy link
Contributor

There is a reason for not including EuclideanRing and DivisionRing: there’s no clear way of defining division when you have more than one field in the record. What should { a:1, b:2, c:3 } / { a:4, b:5, c:6 } be? Note that we can’t do { a: 1/4, b: 2/5; c: 3/6 } because that won’t satisfy the laws. In particular, division needs to be defined for any nonzero divisor, but if you have a zero in at least one field (but not all fields) you have an undefined result.

@hdgarrood
Copy link
Contributor

I think a Bounded instance makes sense, given that we already give records Ord instances.

@kl0tl
Copy link
Member Author

kl0tl commented Feb 8, 2020

Thank you both for your answers 🙇 I added a Bounded instance for records in #208.

@kl0tl kl0tl closed this as completed Feb 8, 2020
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

No branches or pull requests

3 participants