Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. chunk :: (Eq b) => [a] -> (a -> b) -> [(b, [a])]
  2. chunk [] _ = []
  3. chunk (x:xs) f = let fx = f x
  4. (h, t) = span ((==) fx . f) xs
  5. in [(fx,(x:h))] ++ chunk t f
  6.  
  7.  
  8.  
  9. data ChunkType = Word | Blank deriving (Show, Eq)
  10.  
  11. chunkByBlank :: Char -> ChunkType
  12. chunkByBlank ' ' = Blank
  13. chunkByBlank _ = Word
  14.  
  15. main = putStrLn . show $ chunk "Haskell is awesome!!" chunkByBlank
  16. -- => [(Word,"Haskell"),(Blank," "),(Word,"is"),(Blank," "),(Word,"awesome!!")]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement