~ubuntu-branches/ubuntu/precise/ghc/precise

« back to all changes in this revision

Viewing changes to libraries/bytestring/tests/groupby.hs

  • Committer: Bazaar Package Importer
  • Author(s): Joachim Breitner
  • Date: 2011-01-17 12:49:24 UTC
  • Revision ID: james.westby@ubuntu.com-20110117124924-do1pym1jlf5o636m
Tags: upstream-7.0.1
ImportĀ upstreamĀ versionĀ 7.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import qualified Data.ByteString.Lazy as P
 
2
import qualified Data.ByteString      as B
 
3
import qualified Data.List            as L
 
4
import Data.Word
 
5
 
 
6
main = do
 
7
    let s = [65..68] ++ [103,103]
 
8
    f s
 
9
    print (length s)
 
10
 
 
11
f s = do
 
12
    print "Should have the same structure:"
 
13
    print $ L.groupBy (/=) $        s
 
14
 
 
15
    flip mapM_ [1..16] $
 
16
        \i -> do putStr ((show i) ++ "\t"); print $ P.groupBy (/=) $ pack i s
 
17
{-# NOINLINE f #-}
 
18
 
 
19
chunk :: Int -> [a] -> [[a]]
 
20
chunk _    [] = []
 
21
chunk size xs = case L.splitAt size xs of (xs', xs'') -> xs' : chunk size xs''
 
22
 
 
23
pack :: Int -> [Word8] -> P.ByteString
 
24
pack n str = P.LPS $ L.map B.pack (chunk n str)