简体   繁体   English

在haskell中打印出列表中元素的索引

[英]Print out the index of elements in a list in haskell

I am new to haskell programming and I am trying to write a program that prints out the index of elements in a list.我是 Haskell 编程的新手,我正在尝试编写一个程序来打印出列表中元素的索引。

Here is the code I have:这是我的代码:

Index :: [Int]->[Int]

Index []= []
Index(x:xs)= 0:index (xs+1)

You mean the following?你的意思是以下?

index :: [a] -> [Int]
index x = [1 .. length x]

[1..4] is shorthand for [1,2,3,4] ... [1..4][1,2,3,4]简写...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM