gitlab-ci: Move hadrian-ghc-in-ghci job first
[ghc.git] / testsuite / tests / typecheck / should_compile / PolyRec.hs
1 -- An example of RelaxedPolyRec in action which came up
2 -- on Haskell Cafe June 2010 (Job Vranish)
3
4 module Foo where
5
6 import Data.Maybe
7
8 -- The fixed point datatype
9 data Y f = Y (f (Y f))
10
11 -- Silly dummy function
12 maybeToInt :: Maybe a -> Int
13 maybeToInt = length . maybeToList
14
15 ---------------------------
16 -- f and g are mutually recursive
17 -- Even though f has a totally monomorphic
18 -- signature, g has a very polymorphic one
19
20 f :: Y Maybe -> Int
21 f (Y x) = g maybeToInt x
22
23 -- With RelaxedPolyRec we can infer this type
24 -- g :: Functor f => (f Int -> b) -> f (Y Maybe) -> b
25 g h x = h $ fmap f x
26
27 -- 'test' checks that g's type is polymorphic enough
28 test :: Functor f => (f Int -> b) -> f (Y Maybe) -> b
29 test = g