类型系列扩展名不起作用

时间:2013-05-02 12:32:53

标签: haskell type-families

the Haskell wiki page for Type Families上,有以下示例列表:

type family F a :: *
type instance F [Int]              = Int         -- OK!
type instance F String             = Char        -- OK!
type instance F (F a)              = a           -- WRONG: type parameter mentions a type family
type instance F (forall a. (a, b)) = b           -- WRONG: a forall type appears in a type parameter
type instance F Float              = forall a.a  -- WRONG: right-hand side may not be a forall type
type instance where                              -- OK!
  F (Maybe Int)  = Int
  F (Maybe Bool) = Bool
  F (Maybe a)    = String
type instance where            -- WRONG: conflicts with earlier instances (see below)
  F Int = Float
  F a   = [a]

type family G a b :: * -> *
type instance G Int            = (,)     -- WRONG: must be two type parameters
type instance G Int Char Float = Double  -- WRONG: must be two type parameters

这表明type instance where是此扩展名下的有效语法。但是,使用GHC 7.4.2时,以下代码无法编译:

{-# LANGUAGE TypeFamilies #-}

type family F a :: *
type instance where
  F (Maybe Int)  = Int
  F (Maybe Bool) = Bool
  F (Maybe a)    = String

错误消息是:

  

test.hs:4:15:输入`where'

时解析错误

由于这是一个解析错误,看起来不支持该语法,所以我错过了一个必要的扩展,还是其他的错误?

1 个答案:

答案 0 :(得分:13)

这似乎是过早记录的情况。根据{{​​3}},这种语法是最近添加到GHC HEAD的功能的一部分,但它在任何已发布的GHC版本中都没有效。