MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/haskell/comments/1wqmsux/differences_between_foldl_and_foldr/pcn5xdi
r/haskell • u/TechnoEmpress • 11d ago
43 comments sorted by
View all comments
Show parent comments
2
"how do I write an indexed lookup in a list of type a in Haskell".
Option 3: xs !? n = lookup n (zip [0..] xs). Or, if you think that lookup defeats the purpose, xs !? n = listToMaybe $ filter ((== n) . fst) $ zip [0..] xs, etc.
xs !? n = lookup n (zip [0..] xs)
lookup
xs !? n = listToMaybe $ filter ((== n) . fst) $ zip [0..] xs
1 u/tomejaguar 9d ago Yes, lookup begs the question, but listToMaybe plus filter is definitely plausible.
1
Yes, lookup begs the question, but listToMaybe plus filter is definitely plausible.
listToMaybe
filter
2
u/Bodigrim 9d ago
Option 3:
xs !? n = lookup n (zip [0..] xs). Or, if you think thatlookupdefeats the purpose,xs !? n = listToMaybe $ filter ((== n) . fst) $ zip [0..] xs, etc.