summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-regress/indexed-types/should_fail/T2664.hs
blob: d5b04a6380a816e3c0c16426acb630a66b0cfd1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{-# LANGUAGE EmptyDataDecls, TypeFamilies, TypeOperators, ScopedTypeVariables #-}
module Overflow where
import Control.Concurrent

data (:*:) a b
data (:+:) a b

data family PChan a
data    instance PChan (a :+: b) = E (IO (PChan a)) (IO (PChan b))
newtype instance PChan (a :*: b) = O (IO (Either (PChan a) (PChan b)))

type family Dual a
type instance Dual (a :+: b) = Dual a :*: Dual b
type instance Dual (a :*: b) = Dual a :+: Dual b

class Connect s where
    newPChan :: (s ~ Dual c, c ~ Dual s) => IO (PChan s, PChan c)

pchoose :: (t -> a) -> MVar a -> IO (t,b) -> IO b
pchoose = undefined

instance (Connect a, Connect b) => Connect (a :*: b) where
    newPChan = do
        v <- newEmptyMVar

        -- This version is in T2664a
        -- correct implementation:
        -- return (O $ takeMVar v, E (pchoose Left v newPChan) (pchoose Right v newPChan))
       
        -- type error leads to stack overflow (even without UndecidableInstances!)
        return (O $ takeMVar v, E (pchoose Right v newPChan) (pchoose Left v newPChan))