我有这种类型的包装功能如何为封装函数的类型编写任意实例?
newtype Transaction d e r = Transaction (d -> Either e (d,r))
...我想为它的函子&应用型实例做快速检查测试,但编译器抱怨说,它不具有任意实例。
我试图这样做,但我坚持生成随机函数。
谢谢!
的快速检查属性这样
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
...和测试定义== == UPDATE看起来是这样的:
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)
[?也许这将是有用的(https://mail.haskell.org/pipermail/haskell- cafe/2010-September/083735.html)但是,我想想你会从这些随机函数中获得什么。我会说,一些边缘案例是这需要的一切。 –