From f6b121abe0b310e3079c03b4634c6558116ff590 Mon Sep 17 00:00:00 2001 From: simonpj Date: Thu, 1 Jul 2010 15:08:27 +0000 Subject: [PATCH] Add a RelaxedPolyRec test ..suggested by Haskell Cafe email (Job Vranish) --- .../typecheck/should_compile/PolyRec.hs | 31 +++++++++++++++++++ .../typecheck/should_compile/all.T | 1 + 2 files changed, 32 insertions(+) create mode 100644 testsuite/tests/ghc-regress/typecheck/should_compile/PolyRec.hs 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 0000000000..6b41de3fb0 --- /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 f468d35bc5..03cc42b2a4 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', -- GitLab