Question

The hmatrix package contains the following type families code:

type family BoundsOf x

type instance BoundsOf (a->a) = Int
type instance BoundsOf (a->a->a) = (Int,Int)

On GHC 7.6, this compiles fine.

On GHC 7.7 (leading to 7.8), we get:

lib/Numeric/ContainerBoot.hs:515:15:
    Conflicting family instance declarations:
      BoundsOf (a -> a) -- Defined at lib/Numeric/ContainerBoot.hs:515:15
      BoundsOf (a -> a -> a)
        -- Defined at lib/Numeric/ContainerBoot.hs:516:15

What kind of "conflict" is meant here? I cannot see the problem with these instances.


Update: Here is a minimal example Test.hs:

{-# LANGUAGE TypeFamilies #-}
module Test where

type family BoundsOf x

type instance BoundsOf (a->a) = Int
type instance BoundsOf (a->a->a) = (Int,Int)

Trying that:

ghci Test.hs       # 7.6, all fine
ghci-7.7 Test.hs   # fails
Was it helpful?

Solution

Akio Takano managed to construct an example program that in GHC 7.6 coerces Int to IO String using the type family declaration

type family F a
type instance F (a -> a) = Int
type instance F (a -> a -> a) = IO String

See http://ghc.haskell.org/trac/ghc/ticket/8162 or https://github.com/takano-akio/type-family-overlap.

OTHER TIPS

To me it looks more like a bug in GHC 7.6 TBH.

If you remove the syntax sugar for function types, what you have is

type instance BoundsOf (((->) a) a) = Int
type instance BoundsOf (((->) a) (((->) a) a)) = (Int, Int)

which looks conflicting...

Now, if I try to pull this same trick with another type constructor instead of ((->) a), I get an error from GHC 7.6 as well:

{-# LANGUAGE TypeFamilies #-}
type family BoundsOf x

type instance BoundsOf (Maybe a) = Int
type instance BoundsOf (Maybe (Maybe a)) = (Int, Int)

Which results in:

tyfams.hs:4:15:
    Conflicting family instance declarations:
      type instance BoundsOf (Maybe a) -- Defined at tyfams.hs:4:15
      type instance BoundsOf (Maybe (Maybe a)) -- Defined at tyfams.hs:5:15

I don't see why it should work for ((->) a).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top