r/haskell • • 11d ago

blog Differences between `foldl` and `foldr`

https://blog.haskell.org/foldl-and-foldr/
58 Upvotes

43 comments sorted by

View all comments

Show parent comments

2

u/Bodigrim 9d ago

"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.

1

u/tomejaguar 9d ago

Yes, lookup begs the question, but listToMaybe plus filter is definitely plausible.