Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A bifunctor class checker to be used with https://hackage.haskell.org/package/checkers-0.4.7
{-# LANGUAGE ScopedTypeVariables #-}
bifunctor :: forall m a b c d e f.
( Bifunctor m
, Arbitrary a, Arbitrary b, Arbitrary c
, Arbitrary d, Arbitrary e, Arbitrary f
, CoArbitrary a, CoArbitrary d
, Show (m a d), Arbitrary (m a d), EqProp (m a d), EqProp (m c f)
) =>
m (a,b,c) (d,e,f) -> TestBatch
bifunctor = const ( "bifunctor"
, [ ("bimap identity", property bimapIdentityP)
, ("first identity" , property firstIdP)
, ("second identity" , property secondIdP)
, ("compose" , property composeP)
]
)
where
bimapIdentityP :: Property
bimapIdentityP = bimap id id =-= (id :: m a d -> m a d)
firstIdP :: Property
firstIdP = first id =-= (id :: m a d -> m a d)
secondIdP :: Property
secondIdP = second id =-= (id :: m a d -> m a d)
composeP :: (a -> c) -> (d -> f) -> Property
composeP f g = bimap f g =-= (first f . second g :: m a d -> m c f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment