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.
Haskell 中是否有一个函数将列表和该列表中的元素作为参数并返回该列表中该元素的索引,即
如果我有列表['a','f','d','g','b','h']和元素'b',它将返回 4?
['a','f','d','g','b','h']
'b'
您正在寻找以下elemIndex功能Data.List:
elemIndex
Data.List
> :m +Data.List > :t elemIndex elemIndex :: Eq a => a -> [a] -> Maybe Int > elemIndex 'c' "abcde" Just 2