orphans

Ian Lynagh igloo at earth.li
Fri Aug 15 16:32:57 EDT 2008


Hi all,

I've been looking at removing some orphan instances (trac #2467) and hit
difficulties.

At the very bottom of the array package we have Data.Array.Base, which
defines:

    class IArray a e where
        ...
        unsafeAccum = ... unsafeAccumST ...
    unsafeAccumST = ... thaw ...
    thaw = ...

Now, higher up in the hierarchy, we have things like IOArrays, for which
we want to magically turn 'thaw' into a specialised version:

    {-# RULES "thaw/IOArray"  thaw = thawIOArray #-}

but this rule is orphaned (as you can use 'thaw' in your program without
GHC knowing that you need the IOArray module).


I think that it would be possible to fix this, by renaming thaw to
safeThaw and defining thaw = safeThaw higher up, in MArray.
In MArray, we would make thaw NOINLINE but manually rewrite it to
safeThaw in phase 2 (actually, I think we can ask GHC to INLINE it
automatically in phase 2?), while in phase 1 we would try to rewrite it
to thawIOArray etc if the types were suitable.

Is this the best way? It seems very heavy, for such a simple problem.

I feel like there should be a simpler way to deorphan it without having
to move it, e.g.
    {-# RULES "thaw/IOArray"
       (thaw :: Array ix e -> IO (IOArray ix e)) = thawIOArray #-}
(although that also clunky with such a large type).

Ideas welcomed!


Thanks
Ian



More information about the Cvs-libraries mailing list