集合の内包表記、タプル

['\t' .. '^']
Prelude> ['\t' .. '^']
"\t\n\v\f\r\SO\SI\DLE\DC1\DC2\DC3\DC4\NAK\SYN\ETB\CAN\EM\SUB\ESC\FS\GS\RS\US !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^"
  • 方程式の近似解を求める
 [x | x <- [-10,-9.9999 .. 10], abs(x^2-6) < 0.001]
Prelude> [x | x <- [-10,-9.9999 .. 10], abs(x^2-6) < 0.001]
[-2.449600000017597,-2.449500000017597,-2.4494000000175973,-2.4493000000175975,2.449299999970986,2.4493999999709857,2.4494999999709854,2.449599999970985]
  • 格子点を作る
[(x,y) | x <- [1..5],y<-[1..5]]
Prelude> [(x,y) | x <- [1..5],y<-[1..5]]
[(1,1),(1,2),(1,3),(1,4),(1,5),(2,1),(2,2),(2,3),(2,4),(2,5),(3,1),(3,2),(3,3),(3,4),(3,5),(4,1),(4,2),(4,3),(4,4),(4,5),(5,1),(5,2),(5,3),(5,4),(5,5)]