Remove the type-checking knot.
[ghc.git] / testsuite / tests / polykinds / T5771.hs
1 {-# LANGUAGE DataKinds, PolyKinds, GADTs, TypeOperators #-}
2 {-# LANGUAGE MultiParamTypeClasses #-}
3
4 module T5771 where
5
6 class IndexedMonad m where
7 unit :: a -> m i i a
8 bind :: m i j a -> (a -> m j k b) -> m i k b
9
10 newtype IndexedIO i j a = IndexedIO {runIndexedIO :: IO a}
11
12 -- i and j are both *; instance is accepted
13 instance IndexedMonad IndexedIO where
14 unit = IndexedIO . return
15 bind m k = IndexedIO $ runIndexedIO m >>= runIndexedIO . k
16 infixl 1 `bind`
17
18 data HList xs where
19 N :: HList '[]
20 (:>) :: a -> HList as -> HList (a ': as)
21 infixr 5 :>
22
23 newtype HLState xs ys a = HLState {runHLState :: HList xs -> (a, HList ys)}
24
25 -- i and j are now [*]; rejected with the MPTCs message
26 instance IndexedMonad HLState where
27 unit x = HLState $ \s -> (x, s)
28 bind (HLState f) k = HLState $ \xs ->
29 case f xs of (a, ys) -> runHLState (k a) ys