summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_fail/LongWayOverlapping.hs
blob: 2d5db860bbd2030e932f6f83e0d61a458347eefd (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
32
33
34
35
36
37
38
39
40
41
42
43
{-# LANGUAGE TypeFamilies, MultiParamTypeClasses
  , FlexibleContexts, FlexibleInstances, UndecidableInstances
  , TypeSynonymInstances, GeneralizedNewtypeDeriving
  #-}

module LongWayOverlapping where


class M a where

class M a => XMLG a

instance M [a]

instance XMLG [m] where     -- Generates an implication wanted:  forall m. M [m]

class M a => EmbAsChild a b where
  emb :: b -> [a]


instance EmbAsChild [Char] Bool where
  emb _ = emb 'c'


  -- This one generates an unsolvable EmbAsChild [Char] Char

-- Original problem is:
-- [w] EmbAsChild [Char] Char
-- [w] forall m. M [m]
-- Now, by converting the wanted to given and pushing it inside the implication
-- we have the following:
-- [g] EmbAsChild [Char] Char
-- [g] M [Char]   <~~ The superclass of the first given!
-- [w] M [m]
-- And now OOPS we can't solve M [m] because we are supposed to delay our choice
-- as much as possible!

-- DV:
-- One possible solution is to STOP PUSHING wanteds as givens inside an implication
-- in a checking context. I think it's the best thing to do and I've implemented it.

-- In inference mode that's ok and the error message is very comprehensible, see
-- test case PushedInFlatsOverlap.hs