[Haskell-cafe] Re: Selecting Array type

Ben Franksen ben.franksen at online.de
Wed Feb 20 16:56:05 EST 2008


Jeff φ wrote:
> However, my implementation of SmartArray requires me to create an instance
> of a selector class to tell the compiler whether the type is boxed or
> unboxed.  I'm hoping to avoid creating instances of the selector class for
> every possible type.  I'd be grateful for any suggestions.

Using ghc-6.8.2 I get

test.hs:30:0:
    Functional dependencies conflict between instance declarations:
      instance [overlap ok] SmartArraySelector UArray Bool
        -- Defined at test.hs:30:0-46
      instance [overlap ok] SmartArraySelector Array e
        -- Defined at test.hs:49:0-40

[more of the same for the other classes omitted]

The offending lines are

instance SmartArraySelector UArray Bool   where

vs.

instance SmartArraySelector Array e where

Note that it explicitly says 'overlap ok' but the functional dependencies
cannot be fulfilled. You defined

class (IArray a e) => SmartArraySelector a e | e -> a

Your generic instance says that it determines the 'a' type for /all/
types 'e' as 'Array'. This conflicts with the other instance which says it
determines the 'a' for the specific type 'Bool' as 'UArray'.

That leaves the question how to achieve what you want, for which
unfortunately I have no answer.

Cheers
Ben



More information about the Haskell-Cafe mailing list