
29 May
2016
29 May
'16
8:42 p.m.
How about (!?) like Data.Vector?
On Sun, May 29, 2016 at 5:21 PM, David Feuer
Data.Sequence offers
index :: Seq a -> Int -> a
which throws an error if the index is out of range. I'd like to add something like
indexMay :: Seq a -> Int -> Maybe a
Aside from the safety factor, indexMay would offer a way to ensure the indexing occurs at a particular time. Much like Data.Vector.indexM, this can help prevent memory leaks. In fact, an analogue of indexM can be implemented in terms of indexMay:
indexM :: Applicative m => Seq a -> Int -> m a indexM xs i = case xs `indexMay` i of Nothing -> error "indexM: index out of range" Just x -> pure x