gpt4 book ai didi

haskell - 类型系列扩展无法按描述工作

转载 作者:行者123 更新时间:2023-12-02 05:26:49 25 4
gpt4 key购买 nike

关于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: parse error on input `where'

由于这是一个解析错误,看起来该语法不受支持,所以我是否缺少必要的扩展,或者是否有其他问题?

最佳答案

这似乎是一个过早记录的情况。根据this blog post ,此语法是最近添加到 GHC HEAD 的功能的一部分,但它在任何已发布的 GHC 版本中尚未有效。

关于haskell - 类型系列扩展无法按描述工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16338175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com