[Haskell-cafe] How to devide matrix into small blocks

Janis Voigtlaender voigt at tcs.inf.tu-dresden.de
Fri Jun 15 02:38:17 EDT 2007


Daniel Fischer wrote:
> What about
> 
> blocks w h = concatMap transpose . map (map (chop w)) . chop h

Seems right. I arrived at something else:

divide w h ls = concatMap (foldr (zipWith (:) . chop w) (repeat []))
                           (chop h ls)

That uses fewer intermediate lists, and indeed should be equivalent to 
the above up to some fusion calculations (fusing concatMap with map, and 
fusing the foldr-based definition of transpose with the remaining map).

Ciao, Janis.

-- 
Dr. Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:voigt at tcs.inf.tu-dresden.de


More information about the Haskell-Cafe mailing list