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

Is there a similar typeclass in Purescript?

up vote 5 down vote accepted

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.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.