I'm trying to adapt Discipline's testing approach, but I'm experiencing issues with comparing values in effectful context
The source of the problem is in discipline package in cats laws - there is an implicit converter from
Prop, requiring an
Eq[A] and a prettifier
A => Pretty.
A is actually an
IO[A], it means that to use
Pretty I have to reevaluate the effects I've already evaluated with
Eq or memoize them. I suppose I can come up with my own converter to
Prop which runs all effects and remembers their values at the beginning, but maybe I'm missing something and someone here can point me in the right direction.
PartialOrder also enables >, >=, <, and <= operators, but these are tricky to use because if you’re not careful you could end up using the built-in comparison operators.
Hmm. I didn’t see any cases of that problem in my usage.
On a related note: if you’re wirting tests and you need an
MonadError, do you just jump to using
IO (or, in my situation,
StateT[IO, MyState, ?] because I need
MonadError)? Or something less powerful than
Eitheris a pretty easy one
Coyonedaas well, so it's actually closer to
a good way of looking at it is noting how
Monad can be expressed as either (forgetting
class Functor f => Monad f where pure :: a -> f a join :: f (f a) -> f a
class Monad f where pure :: a -> f a (>>=) :: f a -> (a -> f b) -> f b
The first definition gives rise to
data Free f a = Pure a | Roll (f (Free f a)) instance Functor f => Monad (Free f) where ...
and your algebra looks this way:
data Alg a = Put String a | Get String (String -> a) instance Functor Alg where
The second definition, which is
Operational (and cats Free) gives rise to
data Free f a where Pure :: a -> Free fa FlatMap :: f a -> (a -> Free f b) -> Free f b instance Monad (Free f a) -- note no Functor
and your algebra looks this way
data Alg a where Put :: String -> Alg () Get :: String -> Alg String
and no Functor needed