You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find it peculiar that the monad here is not explicitly exposed, nor even mentioned in the docs. I currently have a module where I define it myself:
newtype Tiers a = Tiers {unTiers::[[a]]} deriving Functor
instance Applicative Tiers where
pure = return
(<*>) = ap
instance Monad Tiers where
return x = Tiers [[x]]
Tiers mx >>= k = Tiers $ concatMapT (unTiers . k) mx
instance Alternative Tiers where
Tiers mx <|> Tiers my = Tiers $ mx \/ my
empty = Tiers []
This allows me to much more easily define Listable instances using do-notation when the allowed elements of a certain data type depend on (and perhaps modify) some state. In my case, I have a state type and another data type representing changes to the state, and for changes to be valid they must be applicable to the current state.
Having these instances also helps to convert existing QC Arbitrary instances to Listable, since Tiers corresponds exactly to QC's Gen monad. In fact, if you don't use any special features of Gen you may generalize your existing code to work with any given generator monad.
Finally, note that this Monad instance is quite different from the one we get without the newtype wrapper (via the standard instance for lists). The latter is in fact quite useless.
The text was updated successfully, but these errors were encountered:
Yes. I am using leancheck's operations on tiers for (something like) "fair" logic programming (breadth first traversal of search space, instead of Prolog-like leftmost traversal)
I find it peculiar that the monad here is not explicitly exposed, nor even mentioned in the docs. I currently have a module where I define it myself:
This allows me to much more easily define
Listable
instances using do-notation when the allowed elements of a certain data type depend on (and perhaps modify) some state. In my case, I have a state type and another data type representing changes to the state, and for changes to be valid they must be applicable to the current state.Having these instances also helps to convert existing QC
Arbitrary
instances toListable
, sinceTiers
corresponds exactly to QC'sGen
monad. In fact, if you don't use any special features ofGen
you may generalize your existing code to work with any given generator monad.Finally, note that this Monad instance is quite different from the one we get without the newtype wrapper (via the standard instance for lists). The latter is in fact quite useless.
The text was updated successfully, but these errors were encountered: