私はhspecとQuickCheckを使用してFunctorのインスタンスのファンクション法を検証しています。私は、私は、このようなコードのブロックを使用して、これらの2をテストしてるの機能式の引数として型コンストラクタを指定します
functorIdentity :: (Functor f, Eq (f a)) => f a -> Bool
と
functorComposition :: (Functor f, Eq (f c)) => (Fun a b) -> (Fun b c) -> f a -> Bool
を持っている:
testListFunctorness :: IO()
testListFunctorness =
hspec $ do
describe "list" $ do
it "should obey functor identity" $ do
property (functorIdentity :: [Int] -> Bool)
it "should obey functor composition" $ do
property
(functorComposition :: (Fun Int String) -> (Fun String Int) -> [Int] -> Bool)
事はAの同じ特性を試験するために、あります異なるFunctorのインスタンス、[Int]
以外のすべてをコピーする必要があります。
testMaybeFunctorness :: IO()
testMaybeFunctorness =
hspec $ do
describe "maybe" $ do
it "should obey functor identity" $ do
property (functorIdentity :: Maybe Int -> Bool)
it "should obey functor composition" $ do
property
(functorComposition :: (Fun Int String) -> (Fun String Int) -> Maybe Int -> Bool)
異なるFunctor
インスタンスに対して多形性のある式を書くことができるはずですが、それをどのように開始するか考えることさえできません。
複数の異なるFunctor
にテストロジックのブロックを簡単に再利用するにはどうすればよいですか?あなたは何ができるか
私はここでABの問題があると確信していますが、私はBが何であるか見ることができません:) – N3dst4