私は機能関数をラップする型に任意のインスタンスを書き込む方法は?
newtype Transaction d e r = Transaction (d -> Either e (d,r))
をラップし、このタイプを持っている...と私はそののFunctor & Applicativeのインスタンスにquickcheckテストをやってみたいけど、コンパイラが、それは任意のインスタンスを持っていないと文句を言い。
私はそうしようとしましたが、私はランダム関数を生成することに固執しています。
ありがとうございます!
== UPDATE ==
quickcheckプロパティがこの
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
のように定義されている...とテストは次のようになります。
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)私はあなたが本当にそのようなランダムな機能から得ようとしているものについて考えています。私は、いくつかの重要なケースは、これが必要とするすべてのものだと言いたいと思います。 –