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