diff options
Diffstat (limited to 'testsuite/tests/quantified-constraints/T15290.hs')
-rw-r--r-- | testsuite/tests/quantified-constraints/T15290.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/testsuite/tests/quantified-constraints/T15290.hs b/testsuite/tests/quantified-constraints/T15290.hs new file mode 100644 index 0000000000..8a0c3d989f --- /dev/null +++ b/testsuite/tests/quantified-constraints/T15290.hs @@ -0,0 +1,35 @@ +{-# LANGUAGE TypeApplications, ImpredicativeTypes, ScopedTypeVariables, + QuantifiedConstraints, StandaloneDeriving, GeneralizedNewtypeDeriving #-} + +module T15290 where + +import Prelude hiding ( Monad(..) ) +import Data.Coerce ( Coercible, coerce ) + +class Monad m where + join :: m (m a) -> m a + +newtype StateT s m a = StateT { runStateT :: s -> m (s, a) } + +newtype IntStateT m a = IntStateT { runIntStateT :: StateT Int m a } + +instance Monad m => Monad (StateT s m) where + join = error "urk" + +instance (Monad m, forall p q. Coercible p q => Coercible (m p) (m q)) + => Monad (IntStateT m) where + +-- Fails with the impredicative instantiation of coerce, succeeds without + +-- Impredicative version (fails) +-- join = coerce +-- @(forall a. StateT Int m (StateT Int m a) -> StateT Int m a) +-- @(forall a. IntStateT m (IntStateT m a) -> IntStateT m a) +-- join + + +-- Predicative version (succeeds) + join = (coerce + @(StateT Int m (StateT Int m a) -> StateT Int m a) + @(IntStateT m (IntStateT m a) -> IntStateT m a) + join) :: forall a. IntStateT m (IntStateT m a) -> IntStateT m a |