
8 Jun
2010
8 Jun
'10
6:13 a.m.
R J wrote:
What's an elegant definition of a Haskell function that takes two strings and returns "Nothing" in case the first string isn't a substring of the first, or "Just i", where i is the index number of the position within the first string where the second string begins?
Thomas Hartman wrote:
If you want to use libs to make your life easier, maybe something along these lines? Prelude Data.List.Split Safe> ...
True, those are both very nice libraries. It's just about as easy to do this with the more standard ones, though: Prelude Data.List Data.Maybe> listToMaybe . map fst . filter (("asdf" `isPrefixOf`) . snd) . zip [0..] . tails $ "blee blah asdf bloo" Just 10 Regards, Yitz