OK, when I wrote the question, I understand a simple way to implement this (without arrows, boo!)
longest [] = error "it ambiguous" longest [xs] = xs longest xss = longest . filter (not . null) . map (drop 1) $ xss
Except for this problem ... it discards the first part of the list and does not restore it!
> take 3 $ longest [[1],[1],[1..2^1000],[1]] [2,3,4]
More bookkeeping required: P
longest xs = longest' $ map (\x -> (x,x)) xs longest' [] = error "it ambiguous" longest' [xs] = fst xs longest' xss = longest . filter (not . null . snd) . map (sndMap (drop 1)) $ xss sndMap f (x,y) = (x, fy)
Now it works.
> take 3 $ longest [[1],[1],[1..2^1000],[1]] [1,2,3]
But no arrows. :( If this can be done with arrows, then hopefully this answer can give you a place to start.
source share