Testsuite: tabs -> spaces [skip ci]
[ghc.git] / testsuite / tests / typecheck / should_compile / tc151.hs
1 {-# LANGUAGE RankNTypes #-}
2
3 -- A test for rank-3 types
4
5 module ShouldCompile where
6
7 data Fork a = ForkC a a
8
9 mapFork :: forall a1 a2 . (a1 -> a2) -> (Fork a1 -> Fork a2)
10 mapFork mapA (ForkC a1 a2) = ForkC (mapA a1) (mapA a2)
11
12 data SequF s a = EmptyF | ZeroF (s (Fork a)) | OneF a (s (Fork a))
13 newtype HFix h a = HIn (h (HFix h) a)
14
15 type Sequ = HFix SequF
16
17 mapSequF :: forall s1 s2 . (forall b1 b2 . (b1 -> b2) -> (s1 b1 -> s2 b2))
18 -> (forall a1 a2 . (a1 -> a2) -> (SequF s1 a1 -> SequF s2 a2))
19 mapSequF mapS mapA EmptyF = EmptyF
20 mapSequF mapS mapA (ZeroF as) = ZeroF (mapS (mapFork mapA) as)
21 mapSequF mapS mapA (OneF a as)= OneF (mapA a) (mapS (mapFork mapA) as)
22
23 mapHFix :: forall h1 h2 . (forall f1 f2 . (forall c1 c2 . (c1 -> c2) -> (f1 c1 -> f2 c2))
24 -> (forall b1 b2 . (b1 -> b2) -> (h1 f1 b1 -> h2 f2 b2)))
25 -> (forall a1 a2 . (a1 -> a2) -> (HFix h1 a1 -> HFix h2 a2))
26 mapHFix mapH mapA (HIn v) = HIn (mapH (mapHFix mapH) mapA v)
27
28 mapSequ :: forall a1 a2 . (a1 -> a2) -> (Sequ a1 -> Sequ a2)
29 mapSequ = mapHFix mapSequF
30