Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Purescript typeclass generalizing integers?

Haskell has the Integral typeclass which includes Integer, Int, Int32, Int64, Natural, etc.

Is there a similar typeclass in Purescript?

like image 385
Chris Martin Avatar asked Dec 08 '25 14:12

Chris Martin


1 Answers

We don't have any integer-specific classes in PureScript, but there is a hierarchy of numeric classes:

Numeric hierarchy

Each class adds laws, so although the CommutativeRing and Field classes have no operations they are not redundant.

Any type that is a EuclideanRing also satisfies the laws for integral domains, which generalise integers, so I think that should suit your needs.

Fields have non-zero multiplicative inverses: mod a b = 0 for all a and b, so using that constraint would rule out the possibility of integer division, etc. if that's what you're looking for, so you definitely don't want to that far down the hierarchy.

like image 68
gb. Avatar answered Dec 11 '25 22:12

gb.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!