Re: [Haskell-cafe] Function to find a substring

2010-06-08 Thread Jürgen Doser
El dom, 06-06-2010 a las 15:51 +, R J escribió: > 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

Re: [Haskell-cafe] Function to find a substring

2010-06-08 Thread Tillmann Rendel
Hi, 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? The naive alg

Re: [Haskell-cafe] Function to find a substring

2010-06-08 Thread Yitzchak Gale
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 Ha

Re: [Haskell-cafe] Function to find a substring

2010-06-07 Thread Thomas Hartman
If you want to use libs to make your life easier, maybe something along these lines? Prelude Data.List.Split Safe> fmap length . headMay . split (onSublist "asdf") $ "blee blah asdf bloo" Just 10 If they are big strings, it's probably faster to use bytestrings, or arrays of some kinds, rather tha

[Haskell-cafe] Function to find a substring

2010-06-07 Thread R J
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?