Elm 中其他类型列表的类型别名
Type alias for list of other types in Elm
如果我尝试定义新的类型别名,例如,按以下方式:
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 中为列表定义类型别名?
与某些其他语言(例如 [=20=)不同,Elm 不使用方括号作为其列表类型的特殊表示法。因此,正如编译器告诉您的那样,它无法在期望看到类型的上下文中理解 [
。
类型改为 List Int
,例如您可以在 Elm guide.
中找到
所以只需将您的代码更改为:
type alias ListOfInts = List Int
如果我尝试定义新的类型别名,例如,按以下方式:
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 中为列表定义类型别名?
与某些其他语言(例如 [=20=)不同,Elm 不使用方括号作为其列表类型的特殊表示法。因此,正如编译器告诉您的那样,它无法在期望看到类型的上下文中理解 [
。
类型改为 List Int
,例如您可以在 Elm guide.
所以只需将您的代码更改为:
type alias ListOfInts = List Int