类型系列扩展名不起作用

Dyl*_*lan 9 haskell type-families

类型系列的Haskell维基页面上,有以下示例列表:

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
Run Code Online (Sandbox Code Playgroud)

这表明这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
Run Code Online (Sandbox Code Playgroud)

错误消息是:

test.hs:4:15:输入`where'解析错误

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

ham*_*mar 13

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

  • @Dylan:7.6.3是一个错误修正版本.下一个重要版本将是7.8.1,应包括此功能,并计划在今年晚些时候发布. (2认同)