Hi,

Am Donnerstag, den 01.12.2011, 11:28 +0100 schrieb Joachim Breitner:
> Now I’d like to implement streaks in terms of build and foldr such that
> it is subject to list fusion.

one half of the task is quite doable:

        streaks' :: [Integer] -> [[Integer]]
        streaks' xs = foldr streaksF [] xs
        
        streaksF :: Integer -> [[Integer]] -> [[Integer]]
        streaksF i [] = [[i]]
        streaksF i ([x]:ys) = [i,x]:ys
        streaksF i ((x1:x2:xs):ys) = if i `compare` x1 == x1 `compare`
        x2
                                     then (i:x1:x2:xs):ys
                                     else [i]:(x1:x2:xs):ys

so I can make streaks a somewhat well-behaving consumer. The task to
create the lists using build remains.

(The function only works correctly on lists where no two adjacent
elements are the same, and it behaves differently than the code in the
first mail on [2,1,2]; it builds [[2],[1,2]] instead of [[2,1],2]. That
is ok for my purposes.)

Greetings,
Joachim

-- 
Joachim "nomeata" Breitner
  m...@joachim-breitner.de  |  nome...@debian.org  |  GPG: 0x4743206C
  xmpp: nome...@joachim-breitner.de | http://www.joachim-breitner.de/

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to