我对箭头以及它在数据构造函数中的实际含义感到困惑。我很惊讶它甚至被编译了,但我不知道如何使用它。
如果我试图将其用作数据构造函数的名称,它将无法解析,并且我不确定如何解释它。如果我将其解释为函数类型,那么数据构造函数没有名称,这对我来说也没有意义。
data Type
= TBool
| TInt
| Arrow Type Type
| (->) Type Type
test :: Type
test = Arrow TBool TInt -- Ok
test' :: Type
test' = (->) TBool TInt -- Parse Error on input '->'发布于 2019-07-26 18:05:01
在您提供的用例中,它看起来确实像一个GHC bug (感谢Kevin Buhr的报道)。
便笺
这不能用GADTs解析
data Type where
TBool :: Type
TInt :: Type
Arrow :: Type -> Type -> Type
(->) :: Type -> Type -> Type发布于 2019-07-26 22:28:13
正如@leftaroundabout评论的那样,根据this的说法,你必须添加一个:来创建中缀构造函数:并且根据this question
与数据构造函数不同,不允许使用中缀类型构造函数(除了(->))。
所以举个例子,这是行不通的:
data Type
= TBool
| TInt
| Arrow Type Type
| (-**) Type Type
test :: Type
test = Arrow TBool TInt -- Ok
test' :: Type
test' = (-**) TBool TInt但这将会:
data Type
= TBool
| TInt
| Arrow Type Type
| (:-**) Type Type
test :: Type
test = Arrow TBool TInt -- Ok
test' :: Type
test' = (:-**) TBool TInt还有这个:
data Type
= TBool
| TInt
| Arrow Type Type
| (:-*) Type Type
test :: Type
test = Arrow TBool TInt -- Ok
test' :: Type
test' = (:-*) TBool TInt在您的情况下,您将需要类似以下内容:
data Type
= TBool
| TInt
| Arrow Type Type
| (:->) Type Type
test :: Type
test = Arrow TBool TInt -- Ok
test' :: Type
test' = (:->) TBool TInthttps://stackoverflow.com/questions/57213096
复制相似问题