3

hmatrix软件包包含以下类型系列代码:

type family BoundsOf x

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

在 GHC 7.6 上,这编译得很好。

在 GHC 7.7(导致 7.8)上,我们得到:

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

这里的“冲突”是什么意思?我看不到这些实例的问题。


更新:这是一个最小的例子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)

尝试这样做:

ghci Test.hs       # 7.6, all fine
ghci-7.7 Test.hs   # fails
4

2 回答 2

1

对我来说,它看起来更像是 GHC 7.6 TBH 中的错误。

如果您删除函数类型的语法糖,您所拥有的是

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

这看起来很矛盾......

现在,如果我尝试使用另一个类型的构造函数而不是 来实现相同的技巧((->) a),我也会从 GHC 7.6 中得到一个错误:

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

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

结果是:

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

我不明白为什么它应该为((->) a).

于 2013-08-22T01:50:41.390 回答
1

Akio Takano 设法构建了一个示例程序,在 GHC 7.6 中强制Int使用IO String类型族声明

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

请参阅http://ghc.haskell.org/trac/ghc/ticket/8162https://github.com/takano-akio/type-family-overlap

于 2013-08-23T14:32:54.347 回答