polysemy-1.3.0.0: Higher-order, low-boilerplate, zero-cost free monads.

Polysemy.Law

Synopsis

# Documentation

data Law e r where Source #

A law that effect e must satisfy whenever it is in environment r. You can use runLaw to transform these Laws into QuickCheck-able Propertys.

Constructors

 Law A pure Law, that doesn't require any access to IO. Fields:: (Eq a, Show a, Citizen i12n (Sem r x -> a), Citizen res (Sem (e ': r) x)) => i12nAn interpretation from Sem r x down to a pure value. This is likely run.-> StringA string representation of the left-hand of the rule. This is a formatted string, for more details, refer to printf.-> resThe left-hand rule. This thing may be of type Sem (e ': r) x, or be a function type that reproduces a Sem (e ': r) x. If this is a function type, it's guaranteed to be called with the same arguments that the right-handed side was called with.-> StringA string representation of the right-hand of the rule. This is a formatted string, for more details, refer to printf.-> resThe right-hand rule. This thing may be of type Sem (e ': r) x, or be a function type that reproduces a Sem (e ': r) x. If this is a function type, it's guaranteed to be called with the same arguments that the left-handed side was called with.-> Law e r LawIO Like Law, but for IO-accessing effects. Fields:: (Eq a, Show a, Citizen i12n (Sem r x -> IO a), Citizen res (Sem (e ': r) x)) => i12nAn interpretation from Sem r x down to an IO value. This is likely runM.-> StringA string representation of the left-hand of the rule. This is a formatted string, for more details, refer to printf.-> resThe left-hand rule. This thing may be of type Sem (e ': r) x, or be a function type that reproduces a Sem (e ': r) x. If this is a function type, it's guaranteed to be called with the same arguments that the right-handed side was called with.-> StringA string representation of the right-hand of the rule. This is a formatted string, for more details, refer to printf.-> resThe right-hand rule. This thing may be of type Sem (e ': r) x, or be a function type that reproduces a Sem (e ': r) x. If this is a function type, it's guaranteed to be called with the same arguments that the left-handed side was called with.-> Law e r

runLaw :: InterpreterFor e r -> Law e r -> Property Source #

Produces a QuickCheck-able Property corresponding to whether the given interpreter satisfies the Law.

class MakeLaw e r where Source #

A typeclass that provides the smart constructor mkLaw.

Methods

mkLaw :: (Eq a, Show a, Citizen res (Sem (e ': r) a)) => String -> res -> String -> res -> Law e r Source #

A smart constructor for building Laws.

Instances
 MakeLaw e ([] :: [Effect]) Source # Instance detailsDefined in Polysemy.Law MethodsmkLaw :: (Eq a, Show a, Citizen res (Sem (e ': []) a)) => String -> res -> String -> res -> Law e [] Source # MakeLaw e (Embed IO ': ([] :: [(Type -> Type) -> Type -> Type])) Source # Instance detailsDefined in Polysemy.Law MethodsmkLaw :: (Eq a, Show a, Citizen res (Sem (e ': (Embed IO ': [])) a)) => String -> res -> String -> res -> Law e (Embed IO ': []) Source #

class Citizen r a | r -> a where Source #

Associates the name r with the eventual type a. For example, Citizen (String -> Bool) Bool can produce arbitrary Bools by calling the given function with arbitrary Strings.

Methods

getCitizen :: r -> r -> Gen ([String], (a, a)) Source #

Generate two as via two rs. Additionally, produce a list of strings corresponding to any arbitrary arguments we needed to build.

Instances
 (Arbitrary a, Show a, Citizen b r) => Citizen (a -> b) r Source # Instance detailsDefined in Polysemy.Law MethodsgetCitizen :: (a -> b) -> (a -> b) -> Gen ([String], (r, r)) Source # Citizen (Sem r a -> b) (Sem r a -> b) Source # Instance detailsDefined in Polysemy.Law MethodsgetCitizen :: (Sem r a -> b) -> (Sem r a -> b) -> Gen ([String], (Sem r a -> b, Sem r a -> b)) Source # Citizen (Sem r a) (Sem r a) Source # Instance detailsDefined in Polysemy.Law MethodsgetCitizen :: Sem r a -> Sem r a -> Gen ([String], (Sem r a, Sem r a)) Source #

printf :: String -> [String] -> String Source #

A bare-boned implementation of printf. This function will replace tokens of the form "%n" in the first string with args !! n.

This will only work for indexes up to 9.

For example:

>>> printf "hello %1 %2% %3 %1" ["world", "50"]
"hello world 50% %3 world"