Skip to content

Instantly share code, notes, and snippets.

@robertjlooby
Created June 23, 2017 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertjlooby/b1af43dc8af1759bad4e4c12b9cc0304 to your computer and use it in GitHub Desktop.
Save robertjlooby/b1af43dc8af1759bad4e4c12b9cc0304 to your computer and use it in GitHub Desktop.
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