箭头(->)作为Haskell数据构造函数

bob*_*uza 10 haskell

我对箭头及其在数据构造函数中的实际含义感到困惑。我什至对它进行编译感到惊讶,但我不知道如何使用它。

如果我尝试将其用作数据构造函数的名称,则它不会解析,并且我不确定如何进一步解释它。如果我将其解释为函数类型,则数据构造函数没有名称,这对我也没有意义。

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

leh*_*ins 2

在您提供的用例中,它确实看起来像GHC 错误(感谢 Kevin Buhr 报告)。

笔记

这确实无法解析GADTs

data Type where
  TBool :: Type
  TInt :: Type
  Arrow :: Type -> Type -> Type
  (->) :: Type -> Type -> Type
Run Code Online (Sandbox Code Playgroud)