为什么我不能使用[1] :: [1]但是[1] :: [1] :: []?
我尝试去做[1] :: [1]。得到这个错误:
Error: This expression has type int but an expression was expected of type int list
Run Code Online (Sandbox Code Playgroud)
当我这样做时,[1] :: [1] :: []我得到这个:- : int list list = [[1]; [1]]
[]是空列表x :: []是相同的[x]x :: [y]x :: y :: []与 和相同 [x; y]以你的具体例子:
[1] :: []是相同的[[1]][1] :: [1] :: []是相同的[[1]; [1]][1] :: [1][1] :: 1 :: []与and相同[[1]; 1],但不能有包含混合类型的列表。