sign-0.4.3: Arithmetic over signs and sets of signs

Copyright(c) Masahiro Sakai 2013
Portabilitynon-portable (FlexibleInstances, DeriveDataTypeable, CPP)
Safe HaskellSafe




This module provides arithmetic over signs (i.e. {-, 0, +}) and set of signs.

For the purpose of abstract interpretation, it might be convenient to use Lattice instance. See also lattices package (


The Sign data type

Operations over signs

negate :: Sign -> Sign Source

Unary negation.

abs :: Sign -> Sign Source

Absolute value.

mult :: Sign -> Sign -> Sign Source


recip :: Sign -> Sign Source

Reciprocal fraction.

div :: Sign -> Sign -> Sign Source

Fractional division.

pow :: Integral x => Sign -> x -> Sign Source

Exponentiation s^x.

Note that we define pow Zero 0 = Pos assuming 0^0 = 1.

signOf :: Real a => a -> Sign Source

Sign of a number.

symbol :: Sign -> String Source

Mnemonic symbol of a number.

This function returns "-", "0", "+" respectively for Neg, Zero, Pos.

Operations over sets of signs

Set Sign is equipped with instances of Num and Fractional. Therefore arithmetic operations can be applied to Set Sign.

Instances of Lattice and BoundedLattice are also provided for the purpose of abstract interpretation.