unique-logic-0.2: Solve simple simultaneous equations

Safe HaskellNone

UniqueLogic.ST.Expression

Contents

Synopsis

Documentation

data T s a Source

An expression is defined by a set of equations and the variable at the top-level. The value of the expression equals the value of the top variable.

Instances

Fractional a => Fractional (T s a) 
Fractional a => Num (T s a) 

Construct primitive expressions

constant :: a -> T s aSource

Make a constant expression of a simple numeric value.

Operators from rules with small numbers of arguments

fromRule1 :: (Variable s a -> M s ()) -> T s aSource

fromRule2 :: (Variable s a -> Variable s b -> M s ()) -> T s a -> T s bSource

fromRule3 :: (Variable s a -> Variable s b -> Variable s c -> M s ()) -> T s a -> T s b -> T s cSource

Operators from rules with any number of arguments

data Apply s f Source

Instances

arg :: T s a -> Apply s (Variable s a)Source

This function allows to generalize fromRule2 and fromRule3 to more arguments using Applicative combinators.

Example:

 fromRule3 rule x y
    = runApply $ liftA2 rule (arg x) (arg y)
    = runApply $ pure rule <*> arg x <*> arg y

Building rules with arg provides more granularity than using auxiliary pair rules!

runApply :: Apply s (Variable s a -> M s ()) -> T s aSource

Predicates on expressions

(=:=) :: Eq a => T s a -> T s a -> M s ()Source

Common operators (see also Num and Fractional instances)

(=!=) :: Eq a => T s a -> T s a -> T s aSource

sqr :: Floating a => T s a -> T s aSource

sqrt :: Floating a => T s a -> T s aSource

max :: Ord a => T s a -> T s a -> T s aSource

We are not able to implement a full Ord instance including Eq superclass and comparisons, but we need to compute maxima.

maximum :: Ord a => [T s a] -> T s aSource

pair :: T s a -> T s b -> T s (a, b)Source

Construct or decompose a pair.