summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_compile/tc179.hs
blob: 76fed3e7646d068b7a4e15524f5fdb2582d7245a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{-# LANGUAGE ExistentialQuantification, FlexibleInstances, UndecidableInstances #-}

-- Tests context reduction for existentials

module TestWrappedNode where

class Foo a where { op :: a -> Int }

instance {-# OVERLAPPABLE #-} Foo a => Foo [a] where    -- NB overlap
  op (x:xs) = op x
instance {-# OVERLAPPING #-} Foo [Int] where            -- NB overlap
  op x = 1

data T = forall a. Foo a => MkT a

f :: T -> Int
f (MkT x) = op [x,x]
        -- The op [x,x] means we need (Foo [a]).  We used to
        -- complain, saying that the choice of instance depended on
        -- the instantiation of 'a'; but of course it isn't *going*
        -- to be instantiated.