elementAt :: [a] -> Int -> a
elementAt list i = list !! (i-1)
此函数返回列表的第 i 个元素。例如 elementAt "haskell"5 return 'e' 谁能帮我解释一下“!!”是什么意思,我到处都找不到它。
最佳答案
!!
是一个返回列表中第 i
个元素的函数(从 0 开始索引)。
它的文档可以找到 here :
List index (subscript) operator, starting from 0. It is an instance of the more general
genericIndex
, which takes an index of any integral type.
关于haskell - Haskell 中 "!!"的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41005786/