[Haskell-cafe] Function to find a substring

Jürgen Doser jurgen.doser at gmail.com
Tue Jun 8 09:22:36 EDT 2010


El dom, 06-06-2010 a las 15:51 +0000, 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 the second string begins?
> 
import Data.List

f a b = findIndex (a `isPrefixOf`) (tails b)


	Jürgen



More information about the Haskell-Cafe mailing list