lub-0.1.3: information operators: least upper bound (lub) and greatest lower bound (glb)

Stabilityexperimental
Maintainerconal@conal.net

Data.Lub

Contents

Description

Compute least upper bound (lub) of two values, with respect to information content. I.e., merge the information available in each. For flat types (in which all values are either bottom or fully defined), lub is equivalent to unamb.

Synopsis

Least upper bounds

class HasLub a whereSource

Types that support information merging (lub)

Methods

lub :: a -> a -> aSource

Least upper information bound. Combines information available from each argument. The arguments must be consistent, i.e., must have a common upper bound.

lubs :: [a] -> aSource

n-ary lub. Defaults to foldr lub undefined

Instances

HasLub Bool 
HasLub Char 
HasLub Double 
HasLub Float 
HasLub Int 
HasLub Integer 
HasLub () 
HasLub a => HasLub [a] 
HasLub a => HasLub (Maybe a) 
HasLub b => HasLub (a -> b) 
(HasLub a, HasLub b) => HasLub (Either a b) 
(HasLub a, HasLub b) => HasLub (a, b) 

flatLub :: a -> a -> aSource

A lub for flat domains. Equivalent to unamb. Handy for defining HasLub instances, e.g.,

   instance HasLub Integer where lub = flatLub

Some useful special applications of lub

parCommute :: HasLub b => (a -> a -> b) -> a -> a -> bSource

Turn a binary commutative operation into that tries both orders in parallel, lub-merging the results. Useful when there are special cases that don't require evaluating both arguments.

Similar to parCommute from Unamb, but uses lub instead of unamb.

ptimes :: (HasLub a, Num a) => a -> a -> aSource

Multiplication optimized for either argument being zero or one, where the other might be expensive/delayed.