packages feed

lawz 0.1 → 0.1.1

raw patch · 3 files changed

+49/−4 lines, 3 files

Files

lawz.cabal view
@@ -1,5 +1,5 @@ name:                lawz-version:             0.1+version:             0.1.1 synopsis:            Common mathematical laws. description:         Library of predicates for property testing. homepage:            https://github.com/cmk/lawz
src/Test/Logic.hs view
@@ -1,7 +1,14 @@+{-# LANGUAGE TypeOperators              #-} module Test.Logic where +import qualified Control.Monad as M (join)+import Data.Tuple (swap)+import Data.Void+ type Rel r b = r -> r -> b +type (+) = Either+ xor :: Bool -> Bool -> Bool xor a b = (a || b) && not (a && b) @@ -20,3 +27,41 @@  (<==>) :: Bool -> Bool -> Bool (<==>) = iff++rgt :: (a -> b) -> a + b -> b+rgt f = either f id+{-# INLINE rgt #-}++rgt' :: Void + b -> b+rgt' = rgt absurd+{-# INLINE rgt' #-}++lft :: (b -> a) -> a + b -> a+lft f = either id f+{-# INLINE lft #-}++lft' :: a + Void -> a+lft' = lft absurd+{-# INLINE lft' #-}++eswap :: (a1 + a2) -> (a2 + a1)+eswap (Left x) = Right x+eswap (Right x) = Left x+{-# INLINE eswap #-}++fork :: a -> (a , a)+fork = M.join (,)+{-# INLINE fork #-}++join :: (a + a) -> a+join = M.join either id+{-# INLINE join #-}++eval :: (a , a -> b) -> b+eval = uncurry $ flip id+{-# INLINE eval #-}++apply :: (b -> a , b) -> a+apply = uncurry id+{-# INLINE apply #-}+
src/Test/Operation/Distributive.hs view
@@ -8,13 +8,13 @@ distributive :: Eq r => (r -> r -> r) -> (r -> r -> r) -> (r -> r -> r -> Bool) distributive = distributive_on (==) +distributive_on :: Rel r b -> (r -> r -> r) -> (r -> r -> r) -> (r -> r -> r -> b)+distributive_on (~~) (#) (%) a b c = ((a # b) % c) ~~ ((a % c) # (b % c))+ -- | \( \forall a, b, c: c \% (a \# b) \equiv (c \% a) \# (c \% b) \) -- distributive' :: Eq r => (r -> r -> r) -> (r -> r -> r) -> (r -> r -> r -> Bool) distributive' = distributive_on' (==)--distributive_on :: Rel r b -> (r -> r -> r) -> (r -> r -> r) -> (r -> r -> r -> b)-distributive_on (~~) (#) (%) a b c = ((a # b) % c) ~~ ((a % c) # (b % c))  distributive_on' :: Rel r b -> (r -> r -> r) -> (r -> r -> r) -> (r -> r -> r -> b) distributive_on' (~~) (#) (%) a b c = (c % (a # b)) ~~ ((c % a) # (c % b))