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

Janis Voigtlaender voigt at tcs.inf.tu-dresden.de
Wed Jun 13 03:13:36 EDT 2007


L.Guo wrote:
> Hi all:
> 
> I already have one matrix of type [[a]] to store one image.
> 
> What I want to do is to devide the image into severial small blocks in same size.

In the sense of dividing an image like

abcd
efgh
ijkl
mnop

into the sequence of images

[
ab
ef
,
cd
gh
,
ij
mn
,
kl
op
]

when the block size is 2?

> To do that, I wrote this tool function.
> 
> chop      :: Int -> [a] -> [[a]]
> chop _ [] = []
> chop n ls = take n ls : chop n (drop n ls)
> 
> But I do not know how to use it to write the function.

Hmm, if you have no idea how "chop" could help you to write your
"divide" function, what was your motivation for writing "chop" in the
first place?

Could it be that the following applies:

http://www.haskell.org/haskellwiki/Homework_help ?

If the problem you are trying to solve corresponds to my example above,
it might get you started to think about what you can do by combining tow
applications of "chop" with two applications of "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