[英]Why are type instances (a->a) and (a->a->a) conflicting in GHC 7.8?
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
对我而言,它看起来更像是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)
。
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/8162或https://github.com/takano-akio/type-family-overlap 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.