diff options
Diffstat (limited to 'testsuite/tests/typecheck/should_compile/free_monad_hole_fits.hs')
-rw-r--r-- | testsuite/tests/typecheck/should_compile/free_monad_hole_fits.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_compile/free_monad_hole_fits.hs b/testsuite/tests/typecheck/should_compile/free_monad_hole_fits.hs new file mode 100644 index 0000000000..0fa5b77128 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/free_monad_hole_fits.hs @@ -0,0 +1,25 @@ +{-# OPTIONS_GHC -frefinement-level-hole-fits=2 #-} +{-# LANGUAGE MonoLocalBinds #-} +module TG where +import Prelude ( Monad, Applicative, Functor + , fmap, (<*>), pure, (>>=) + , (=<<), ($), (<$>) ) + +data Free f a = Pure a | Free (f (Free f a)) + +instance Functor f => Functor (Free f) where + fmap f = go where + go (Pure a) = Pure (f a) + -- Should suggest (fmap) + go (Free fa) = Free (_a go fa) + +instance Functor f => Applicative (Free f) where + pure = Pure + Pure a <*> Pure b = Pure (a b) + Pure a <*> Free mb = Free (fmap a <$> mb) + Free ma <*> b = Free ((<*> b) <$> ma) + +instance Applicative f => Monad (Free f) where + Pure a >>= f = f a + -- Should suggest ((=<< (_ :: a -> Free f b)) + Free f >>= g = Free (fmap _a f) |