Skip to content

Instantly share code, notes, and snippets.

@mkscrg
Created September 21, 2013 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mkscrg/6648112 to your computer and use it in GitHub Desktop.
Save mkscrg/6648112 to your computer and use it in GitHub Desktop.
module Main where
import Data.Char
import Data.List
main :: IO ()
main = print $ wordIndexes "Hello test World"
wordIndexes :: String -> [(Int, String)]
wordIndexes s = white 0 s
where
white _ [] = []
white i xs = let (w, xs') = span isSpace xs
in word (i + length w) xs'
word _ [] = []
word i xs = let (w, xs') = break isSpace xs
in (i, w) : white (i + length w) xs'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment