diff --git a/testsuite/tests/ghc-regress/typecheck/should_compile/PolyRec.hs b/testsuite/tests/ghc-regress/typecheck/should_compile/PolyRec.hs new file mode 100644 index 0000000000000000000000000000000000000000..6b41de3fb0077c4c70b96f6d464be6bd673c028e --- /dev/null +++ b/testsuite/tests/ghc-regress/typecheck/should_compile/PolyRec.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE RelaxedPolyRec #-} + +-- An example of RelaxedPolyRec in action which came up +-- on Haskell Cafe June 2010 (Job Vranish) + +module Foo where + +import Data.Maybe + +-- The fixed point datatype +data Y f = Y (f (Y f)) + +-- Silly dummy function +maybeToInt :: Maybe a -> Int +maybeToInt = length . maybeToList + +--------------------------- +-- f and g are mutually recursive +-- Even though f has a totally monomorphic +-- signature, g has a very polymorphic one + +f :: Y Maybe -> Int +f (Y x) = g maybeToInt x + +-- With RelaxedPolyRec we can infer this type +-- g :: Functor f => (f Int -> b) -> f (Y Maybe) -> b +g h x = h \$ fmap f x + +-- 'test' calls g at two different types, f=[] and f=Maybe +test = (g (sum :: [Int] -> Int) [], + g isJust Nothing) diff --git a/testsuite/tests/ghc-regress/typecheck/should_compile/all.T b/testsuite/tests/ghc-regress/typecheck/should_compile/all.T index f468d35bc5484956f083d8d812524afe60beb335..03cc42b2a478236f0c42cb0d84e5fa38e80f86ad 100644 --- a/testsuite/tests/ghc-regress/typecheck/should_compile/all.T +++ b/testsuite/tests/ghc-regress/typecheck/should_compile/all.T @@ -305,6 +305,7 @@ test('T3346', normal, compile, ['']) test('T3391', omit_ways(['profc','profasm']), compile, ['']) test('T3409', normal, compile, ['']) test('T3955', normal, compile, ['']) +test('PolyRec', normal, compile, ['']) test('T2412', extra_clean(['T2412.hi-boot', 'T2412.o-boot',