Instrumenting overlapping instances
Claus Reinke
claus.reinke at talk21.com
Mon Oct 20 19:18:23 EDT 2008
> I'm currently studying the use of overlapping instances, and I was
> hoping to instrument GHC to produce some variety of list of instances
> that overlapped. I haven't done any GHC hacking so far, so I'm not
> entirely familiar with the code base. Does anyone have any guidance
> on which modules I should likely need to modify?
None?-) Loading this
{-# LANGUAGE FlexibleInstances #-}
class C a
instance C a
instance C [a]
instance C [()]
instance C [Bool]
instance C Bool
into ghci 6.8.3, we can play with various types and get ghci to list overlaps
that might match those types. Of course, there are some oddities. Also, the
behaviour will differ slightly if we actually enable OverlappingInstances. But
it should get you started.
Claus
*Main> (undefined :: C a => a)
*** Exception: Prelude.undefined
*Main> (undefined :: C a => a) :: b
<interactive>:1:1:
Overlapping instances for C b
arising from instantiating a type signature at <interactive>:1:1-21
Matching instances:
instance C a
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:3:0-11
instance C Bool
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:7:0-14
instance C [Bool]
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:6:0-16
instance C [()]
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:5:0-14
instance C [a]
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:4:0-13
(The choice depends on the instantiation of `b'
To pick the first instance above, use -fallow-incoherent-instances
when compiling the other instance declarations)
In the expression: (undefined :: (C a) => a) :: b
In the definition of `it': it = (undefined :: (C a) => a) :: b
*Main> (undefined :: C a => a) :: Bool
<interactive>:1:1:
Overlapping instances for C Bool
arising from instantiating a type signature at <interactive>:1:1-21
Matching instances:
instance C a
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:3:0-11
instance C Bool
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:7:0-14
In the expression: (undefined :: (C a) => a) :: Bool
In the definition of `it': it = (undefined :: (C a) => a) :: Bool
*Main> (undefined :: C a => a) :: [b]
<interactive>:1:1:
Overlapping instances for C [b]
arising from instantiating a type signature at <interactive>:1:1-21
Matching instances:
instance C a
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:3:0-11
instance C [a]
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:4:0-13
instance C [Bool]
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:6:0-16
instance C [()]
-- Defined at C:/Documents and Settings/cr3/Desktop/Overlap.hs:5:0-14
In the expression: (undefined :: (C a) => a) :: [b]
In the definition of `it': it = (undefined :: (C a) => a) :: [b]
Claus
More information about the Glasgow-haskell-users
mailing list