Delete ghctags cabal file
[ghc.git] / testsuite / tests / typecheck / should_compile / RebindHR.hs
1 {-# LANGUAGE RebindableSyntax, GADTs, RankNTypes, TypeOperators, ScopedTypeVariables #-}
2
3 module RebindHR where
4
5 import Prelude hiding ( (>>=) )
6 import Data.Typeable
7
8 data Exp = Int Int | Plus Exp Exp | Bool Bool
9 data TExp a where
10 TInt :: Int -> TExp Int
11 TPlus :: TExp Int -> TExp Int -> TExp Int
12 TBool :: Bool -> TExp Bool
13
14 (>>=) :: ((forall t. Typeable t => TExp t -> Maybe r) -> Maybe r)
15 -> (forall t. Typeable t => TExp t -> Maybe r)
16 -> Maybe r
17 x >>= y = x y
18
19 check :: Exp -> (forall t. Typeable t => TExp t -> Maybe r) -> Maybe r
20 check (Int n) k = k (TInt n)
21 check (Bool b) k = k (TBool b)
22 check (Plus e1 e2) k = do te1 :: TExp ty1 <- check e1
23 te2 :: TExp ty2 <- check e2
24 case (eqT :: Maybe (ty1 :~: Int), eqT :: Maybe (ty2 :~: Int)) of
25 (Just Refl, Just Refl) -> k (TPlus te1 te2)
26 _ -> Nothing