haskell - Index contents of a list ([a] -> [(Int, a)]) -


i want function takes in list , indexes out contents: indexed :: [a] -> [(int, a)]. or returned value can whatever monad long contains indexed values of original list.

i thought need statet temporary remember , inclement index numbers while processing each element, i'm not familiar monad transformer thingy , need write function.

i believe similar (this sure not working):

indexed ns =   n <- ns   <-   put (i + 1)   return (i, n) 

how write it?

no need go trouble.

indexed = zip [0..] 

if want use monad transformers, think there’s this:

indexed :: [a] -> [(int, a)] indexed ns = evalstate (runlistt lt) 0     lt =         n <- listt $ return ns         <- <* modify (+1)         return (i, n) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -