From doug at cs.dartmouth.edu Sun Mar 1 23:22:43 2015 From: doug at cs.dartmouth.edu (Doug McIlroy) Date: Sun, 01 Mar 2015 18:22:43 -0500 Subject: definition of List.transpose Message-ID: <201503012322.t21NMhaF032218@coolidge.cs.dartmouth.edu> Not having participated in haskell' before, I'm not sure how to put these perfecting amendments--mot langauge changes--into the pot. Doug McIlroy The specification of List.transpose does not tell what a "column" of a ragged-right list of rows is, either directly or by example. Here is a fuller spec, plus some properties. ----------------------------------------------------- A generalization of the customary matrix operation, transpose returns a list of columns extracted from a list of rows. The jth column of x::[[a]] comprises all extant elements x!!i!!j ordered by i. In the subdomain of list structures that have positive nonincreasing row lengths, e.g. matrices and Young tableaux, transpose . transpose === id (transpose x) !! i !! j === x !! j !! i In general transpose . transpose . transpose === transpose sum . map length . transpose === sum . map length Example: transpose [[10,11],[20],[],[30,31,32]] === [[10,20,30],[11,31],[32]] ----------------------------------------------------- The reference definition can be simplified: transpose xss = case [h | (h:_) <- xss] of [] -> [] hs -> hs : transpose [tss | (_:tss) <- xss] From doug at cs.dartmouth.edu Sun Mar 1 23:39:58 2015 From: doug at cs.dartmouth.edu (Doug McIlroy) Date: Sun, 01 Mar 2015 18:39:58 -0500 Subject: definition of List.transpose Message-ID: <201503012339.t21Ndwg0032315@coolidge.cs.dartmouth.edu> Sorry for a stylistic lapse in a post I just sent from the wrong file. A tail should be called ts, not tss, in the proposed reference definition for List.transpose Doug transpose xss = case [h | (h:_) <- xss] of [] -> [] hs -> hs : transpose [ts | (_:ts) <- xss] From jon.fairbairn at cl.cam.ac.uk Tue Mar 3 10:51:43 2015 From: jon.fairbairn at cl.cam.ac.uk (Jon Fairbairn) Date: Tue, 03 Mar 2015 10:51:43 +0000 Subject: definition of List.transpose References: <201503012322.t21NMhaF032218@coolidge.cs.dartmouth.edu> Message-ID: Doug McIlroy writes: > Not having participated in haskell' before, I'm not sure how > to put these perfecting amendments--mot langauge changes--into > the pot. You might want to try the libraries list rather than Haskell prime for this sort of thing. ? J?n