finding sublist

Serge D. Mechveliani mechvel@botik.ru
Thu, 2 May 2002 11:36:36 +0400


Thanks to people who helped me with the task

>> Import two space separated columns of integers from file.
 
Claus Reinke <claus.reinke@talk21.com> recommends to exploit `lines'.

Indeed, it bocomes shorter now:

  main = readFile "data" >>= (putStr . show . twoIntLists)
    where
    twoIntLists str = case  span (not . null) $ dropWhile null $ lines str
                      of
                        (lns, lns') -> (readInts lns, readInts lns')

    readInts = map (\ str -> read str :: Integer) . dropWhile null


Another question:
has the Haskell Standard library a function for such a usable task
as finding of occurence of a segment in a list? Say 

     findSegmentBy (...) [2,2,3] [0,0,2,2,1,2,2,3,1,2,3] --> 

                                 ([0,0,2,2,1], [2,2,3,1,2,3])

I have heard, an efficient algorithm (for large lists) for this 
is not so simple.

-----------------
Serge Mechveliani
mechvel@botik.ru