[Haskell-cafe] Hamming's Problem

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Tue Jan 22 05:08:20 EST 2008


I wrote:
>      merge' (x:xs) ys = x : merge xs ys
>
>      hammingx = 1 : foldr1 merge' [map (h x) hammingx | x <- hammingx]

Sorry. 'foldr1' is still slightly too strict. (Why doesn't the Haskell
report define foldr1 in terms of foldr?)

The code that works is

    marge' []     ys = ys
    merge' (x:xs) ys = x : merge xs ys

    hammingx = 1 : foldr merge' [] [map (h x) hammingx | x <- hammingx]

I had tested that version, but I assumed the foldr1 version would
be equivalent.

>    which actually works.

And I wrote that without testing. Shame on me.

Bertram


More information about the Haskell-Cafe mailing list