[Haskell-beginners] code critique

Arlen Cuss celtic at sairyx.org
Wed Jul 27 03:19:03 CEST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> Maybe I misunderstood you, but you aren't quite right. In third 
> solution, *list comprehension* will produce all the pairs. But
> you're applying 'null' to it, and since everything in Haskell is lazy
> by default, only *one* pair will be produced.

Good point! Lovely way to show this is with 'trace':

> :m +Debug.Trace null [x | x <- [trace "a" 5, trace "b" 10, trace "c"
> 15]]
False
> null [x | x <- [trace "a" 5, trace "b" 10, trace "c" 15], x > 0]
a
False
> null [x | x <- [trace "a" 5, trace "b" 10, trace "c" 15], x > 5]
a
b
False
> null [x | x <- [trace "a" 5, trace "b" 10, trace "c" 15], x > 10]
a
b
c
False
> 

(Of course, this is less beautifully illustrated with 'length', because
it doesn't actually evaluate the values ...:

> length [trace "a" 5, trace "b" 10, trace "c" 15] == 0
False
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOL2eHAAoJEDiWqExGnQ/QIyMQAK5UhXziU8ctse3K2aUrwrbm
BrQd4ec7i3nCqM0ykkwV9jAAZdHKL3Hu1gWPzH7kBOmcSBcfE3/0woZOna10cSry
jovsAHt5eiE/ujqGWkWeidVSu3wcNcoMXm0ZjdTG5FPx9O+YXvmCRzaxUp0lYZzO
w3tRy4tQPLogcfR72HLlk6IBdG/8d04shQ8lTgRmbRKALI/VN2N8+qqYSsZySiF9
SmE2yQIG3pwSm6QNCCeCGudoz2qjN7SIM4443pjOMJODda1dLpliuC0eo9q+4YSW
ZOH8oJFGembav2C6epYw8qLkSB0bvJltohspZK5GifeSUEWZT36WAbqF0NOAOn6D
du0JW/bEazLiph2NNC2qzqjWDAnoYmY1Nqx3tob2UDMslf8h2H8vMvTiUKKU2tED
h33HgLWfW0l+MPaAvIdTDNscm1/dExleyrtsc6PMA5If650wdjITzHFqQ+9fCYD8
Qbd475cOL5ZkbQjGRlIzgq5goH9JUOv5wqIjz9LOKd1q6KGLq5UN3OTEyjkDt1vo
zGtMjQqgha/M3sznXVUTkBc12gFotVYuUmUCOQFEafjxhtN46JR0fNHJjOFzpqb6
Jkqd75GvOHJCfNUkMc42ZDEWXDzBO38f3Vgouf6VRK+/yDqqOSXyK+/SspQwLuFk
Ph9fI7dGT178rNQpdU3A
=gZUe
-----END PGP SIGNATURE-----



More information about the Beginners mailing list