Instrumenting overlapping instances

J. Garrett Morris jgmorris at cecs.pdx.edu
Mon Oct 27 13:56:11 EDT 2008


Hi,

This is neat - but not quite what I was hoping for.  My intended use
was to build a number of packages and produce a listing of all
overlapping instances, without knowing in advance which classes might
contain overlap.  This is why I was hoping to instrument GHC instead
of using the existing tools like GHCi or my eyes.

Thanks though!

 /g

On Mon, Oct 20, 2008 at 4:18 PM, Claus Reinke <claus.reinke at talk21.com> wrote:
>> 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
>
>



-- 
I am in here


More information about the Glasgow-haskell-users mailing list