I found Jon's definition, which used a state with a "before" list and
an "after" list (a bit like an editor buffer!)  easier to understand
than Mark Jones's.

    >> d acc [] = --  d [] acc would do, but muddles the order;
    >> heads acc ++ d (rests acc) []

    >> d ls (l1:rest) = heads (ls') ++ d (rests ls') rest
    >> where ls' = l1: ls

But maybe I shouldn't have? There is something rather like imperative code
about this kind of auxiliary loop.  One can write some rare old
spaghetti in this style.  Mark's code, which is more "pointfree"
may be easier to reason about, or at any rate easier to manipulate.

> diag  = concat . foldr skew [] . map (map (\x -> [x]))
>         where ... 

-- Peter


Reply via email to