问题描述
例如,如果我尝试通过以下方式定义新类型的别名:
type alias listofInts = [Int]
我收到以下错误:
I was partway through parsing a type alias,but I got stuck here:
11| type alias listofInts = [Int]
^
I was expecting to see a type next. Try putting Int or String for Now?
是否可以为Elm中的列表定义类型别名?
解决方法
与其他某些语言(例如Haskell)不同,Elm不使用方括号作为列表类型的特殊表示法。因此,正如编译器告诉您的那样,在期望看到类型的上下文中,[
毫无意义。
该类型改为写为List Int
,例如您可以在Elm guide中找到。
所以只需将代码更改为此:
type alias ListOfInts = List Int