我正在尝试了解幻影类型。我正在阅读Ralf Hinze的《有趣的幻影类型》。他使用了一个我从未见过且无法编译的关键字with
。当我尝试时,会出现=
的解析错误。
data Type t = RInt with t = Int
| RChar with t = Char
| RList (Type a) with t = [a ]
| RPair (Type a) (Type b) with t = (a, b)
文章前面提到,"with"语句并非必需,可以通过设置a = t
来实现,但是我无法在没有它们的情况下定义这种数据类型。以下错误提示:Not in scope: type variable 'a'
data Type t = RInt
| RChar
| RList (Type a)
| RPair (Type a) (Type b)
我漏掉了什么?