polysemy-1.7.1.0: Higher-order, low-boilerplate free monads.
Safe HaskellNone
LanguageHaskell2010

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))
     
  • => i12n

    An interpretation from Sem r x down to a pure value. This is likely run.

  • -> String

    A string representation of the left-hand of the rule. This is a formatted string, for more details, refer to printf.

  • -> res

    The 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.

  • -> String

    A string representation of the right-hand of the rule. This is a formatted string, for more details, refer to printf.

  • -> res

    The 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))
     
  • => i12n

    An interpretation from Sem r x down to an IO value. This is likely runM.

  • -> String

    A string representation of the left-hand of the rule. This is a formatted string, for more details, refer to printf.

  • -> res

    The 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.

  • -> String

    A string representation of the right-hand of the rule. This is a formatted string, for more details, refer to printf.

  • -> res

    The 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

Instances details
MakeLaw e ('[] :: [Effect]) Source # 
Instance details

Defined in Polysemy.Law

Methods

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

MakeLaw e '[Embed IO] Source # 
Instance details

Defined in Polysemy.Law

Methods

mkLaw :: (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

Instances details
(Arbitrary a, Show a, Citizen b r) => Citizen (a -> b) r Source # 
Instance details

Defined in Polysemy.Law

Methods

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

Citizen (Sem r a -> b) (Sem r a -> b) Source # 
Instance details

Defined in Polysemy.Law

Methods

getCitizen :: (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 details

Defined in Polysemy.Law

Methods

getCitizen :: 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"