Commit f6b121ab authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Add a RelaxedPolyRec test

..suggested by Haskell Cafe email (Job Vranish)
parent f6dd83cc
{-# 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)
......@@ -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, [''])
extra_clean(['T2412.hi-boot', 'T2412.o-boot',
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment