Skip to content

Instantly share code, notes, and snippets.

@edsko
Last active February 25, 2019 15:53
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 edsko/91c9cfb82006b1316bbc65f4983a8c71 to your computer and use it in GitHub Desktop.
Save edsko/91c9cfb82006b1316bbc65f4983a8c71 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -Wall #-}
import Control.Monad.Reader
import Data.Coerce
import Test.QuickCheck.Gen
import Test.QuickCheck.Monadic
hoistGen :: (forall x. n x -> m x) -> Gen (n a) -> Gen (m a)
hoistGen nat (MkGen f) = MkGen $ \gen -> nat . f gen
hoistPropertyM :: (forall x. n x -> m x)
-> (forall x. m x -> n x)
-> PropertyM n a -> PropertyM m a
hoistPropertyM nat natInv (MkPropertyM f) = MkPropertyM $ \g ->
hoistGen nat $ f $ hoistGen natInv . g
hoistLiftedPropertyM :: (MonadTrans t, Monad m, Coercible n (t m))
=> (forall x. t m x -> m x)
-> PropertyM n a -> PropertyM m a
hoistLiftedPropertyM lower = hoistPropertyM lower lift . coerce
hoistReaderPropertyM :: (Monad m, Coercible n (ReaderT r m))
=> r -> PropertyM n a -> PropertyM m a
hoistReaderPropertyM r = hoistLiftedPropertyM (`runReaderT` r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment