unique-logic-0.3: Solve simple simultaneous equations

Safe HaskellSafe
LanguageHaskell98

UniqueLogic.ST.Expression

Contents

Synopsis

Documentation

data T var w 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, Var var, Monoid w) => Fractional (T var w s a) Source # 

Methods

(/) :: T var w s a -> T var w s a -> T var w s a #

recip :: T var w s a -> T var w s a #

fromRational :: Rational -> T var w s a #

(Fractional a, Var var, Monoid w) => Num (T var w s a) Source # 

Methods

(+) :: T var w s a -> T var w s a -> T var w s a #

(-) :: T var w s a -> T var w s a -> T var w s a #

(*) :: T var w s a -> T var w s a -> T var w s a #

negate :: T var w s a -> T var w s a #

abs :: T var w s a -> T var w s a #

signum :: T var w s a -> T var w s a #

fromInteger :: Integer -> T var w s a #

Construct primitive expressions

constant :: (Var var, Monoid w) => a -> T var w s a Source #

Make a constant expression of a simple numeric value.

fromVariable :: var w s a -> T var w s a Source #

Operators from rules with small numbers of arguments

fromRule1 :: (Var var, Monoid w) => (var w s a -> T w s ()) -> T var w s a Source #

fromRule2 :: (Var var, Monoid w) => (var w s a -> var w s b -> T w s ()) -> T var w s a -> T var w s b Source #

fromRule3 :: (Var var, Monoid w) => (var w s a -> var w s b -> var w s c -> T w s ()) -> T var w s a -> T var w s b -> T var w s c Source #

Operators from rules with any number of arguments

data Apply w s f Source #

Instances

Functor (Apply w s) Source # 

Methods

fmap :: (a -> b) -> Apply w s a -> Apply w s b #

(<$) :: a -> Apply w s b -> Apply w s a #

Applicative (Apply w s) Source # 

Methods

pure :: a -> Apply w s a #

(<*>) :: Apply w s (a -> b) -> Apply w s a -> Apply w s b #

liftA2 :: (a -> b -> c) -> Apply w s a -> Apply w s b -> Apply w s c #

(*>) :: Apply w s a -> Apply w s b -> Apply w s b #

(<*) :: Apply w s a -> Apply w s b -> Apply w s a #

arg :: T var w s a -> Apply w s (var w 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 :: (Var var, Monoid w) => Apply w s (var w s a -> T w s ()) -> T var w s a Source #

Predicates on expressions

(=:=) :: (Var var, Monoid w) => T var w s a -> T var w s a -> T w s () infix 0 Source #

Common operators (see also Num and Fractional instances)

(=!=) :: (Var var, Monoid w) => T var w s a -> T var w s a -> T var w s a infixl 4 Source #

sqr :: (Floating a, Var var, Monoid w) => T var w s a -> T var w s a Source #

sqrt :: (Floating a, Var var, Monoid w) => T var w s a -> T var w s a Source #

max :: (Ord a, Var var, Monoid w) => T var w s a -> T var w s a -> T var w s a Source #

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

maximum :: (Ord a, Var var, Monoid w) => [T var w s a] -> T var w s a Source #

pair :: (Var var, Monoid w) => T var w s a -> T var w s b -> T var w s (a, b) Source #

Construct or decompose a pair.