numhask
Safe HaskellNone
LanguageGHC2024

NumHask.Algebra.Patterns

Description

Patterns for common tests

Synopsis

Documentation

pattern Zero :: (Eq a, Additive a) => a Source #

Enabling pattern matching on zero:

isItZero Zero = True
isItZero _    = False

pattern One :: (Eq a, Multiplicative a) => a Source #

Enabling pattern matching on one:

isItOne One = True
isItOne _   = False

pattern MinusOne :: (Eq a, Additive a, Multiplicative a) => a Source #

Enabling pattern matching on minus one:

isItMinusOne MinusOne = True
isItMinusOne _        = False

The means of testing (that is, add one, and check if it equals zero) might be surprising. Other, more obvious, methods would result in underflow errors. (For example, we could negate and test if it's equal to one, but that would fail on any nonzero Natural. Similarly, we could test for equality with the negation of one, but that would fail on any Natural whatsoever, since 'negate one' underflows.)