Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设一个列表的长度为三,我想访问第二个或中间元素。做这个的最好方式是什么?
您可以为此使用列表索引运算符!!,其定义如下:
!!
(!!) : [a] -> Int -> a List index (subscript) operator, starting from 0.
这是一个演示其用法的片段:
first : [Int] -> Int first x = let f = x!!0 in f testFirst = scenario do assert(first [3, 2, 1] == 3)