Ticket #4917: ghc7rankn.hs

File ghc7rankn.hs, 0.7 KB (added by kyagrd, 2 years ago)
Line 
1{-# LANGUAGE GADTs, EmptyDataDecls, RankNTypes #-}
2-- {-# OPTIONS_GHC -F -pgmF she #-}
3data Z
4data S n
5
6-- only works on ghc6 but not on ghc7
7type Const a b = a
8
9{-
10data List a n where
11  Nil :: List a Z
12  Cons :: a -> List a n -> List a (S n)
13-}
14
15data L a l n where
16  N :: L a l Z
17  C :: a -> l n -> L a l (S n)
18
19newtype Fix f n = In { out :: f (Fix f) n }
20
21mcata :: (forall x a . (forall a' . x a' -> Const b a') -> f x a -> Const b a)
22      -> Fix f a -> Const b a
23mcata f = f (mcata f) . out
24
25-- lengthList :: Fix (L e) n -> Int
26lengthList = mcata phi
27 where
28  phi :: (forall n . x n -> Int) -> L e x n -> Int
29  phi len N        = 0
30  phi len (C x xs) = 1 + len xs