I have this type which wraps a function
newtype Transaction d e r = Transaction (d -> Either e (d,r))
...and I want to do quickcheck tests for its Functor & Applicative instances but the compiler complains that it doesn't have an Arbitrary instance.
I tried to do so but I'm stuck at generating the random function.
Thanks!
== UPDATE ==
The quickcheck properties are defined like this
type IdProperty f a = f a -> Bool
functorIdProp :: (Functor f, Eq (f a)) => IdProperty f a
functorIdProp x = (fmap id x) == id x
type CompositionProperty f a b c = f a -> Fun a b -> Fun b c -> Bool
functorCompProp :: (Functor f, Eq (f c)) => CompositionProperty f a b c
functorCompProp x (apply -> f) (apply -> g) = (fmap (g . f) x) == (fmap g . fmap f $ x)
instance (Arbitrary ((->) d (Either e (d, a)))) => Arbitrary (DbTr d e a) where
arbitrary = do
f <- ...???
return $ Transaction f
...and the tests look like this:
spec = do
describe "Functor properties for (Transaction Int String)" $ do
it "IdProperty (Transaction Int String) Int" $ do
property (functorIdProp :: IdProperty (Transaction Int String) Int)
it "CompositionProperty (Transaction Int String) Int String Float" $ do
property (functorCompProp :: CompositionProperty (Transaction Int String) Int String Float)