Order of instances matters in insert_overlapping
The order you pass instances to insert_overlapping
determines the result.
If you modify the TH_Overlaps
test to be something like this
{-# LANGUAGE FlexibleInstances #-}
module Oops where
class C3 a where c3 :: a
instance {-# OVERLAPS #-} C3 [[a]] where c3 = [[]]
instance C3 [[Int]] where c3 = [[1]]
instance C3 [a] where c3 = []
test3 :: [[Int]]
test3 = c3
the program fails with:
S1.hs:11:9: error:
• Overlapping instances for C3 [[Int]] arising from a use of ‘c3’
Matching instances:
instance C3 [[Int]] -- Defined at S1.hs:7:27
instance C3 [a] -- Defined at S1.hs:8:27
• In the expression: c3
In an equation for ‘test3’: test3 = c3
|
11 | test3 = c3
| ^^
but if I swap the order of the instances, it compiles.
{-# LANGUAGE FlexibleInstances #-}
module Oops where
class C3 a where c3 :: a
instance C3 [a] where c3 = []
instance {-# OVERLAPS #-} C3 [[a]] where c3 = [[]]
instance C3 [[Int]] where c3 = [[1]]
test3 :: [[Int]]
test3 = c3