読者です 読者をやめる 読者になる 読者になる

はわわーっ

はわわわわっ

リストするよ

haskell

いろんなリストを作るよ。リスト内包表記とか便利だよ。

main = do
    print $ [1..10]
    -- [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
    print $ [2,4..20]
    -- [2,4,6,8,10,12,14,16,18,20]
    print $ [20,15..1]
    -- [20,15,10,5]

    print $ take 10 [3,6..]
    -- [3,6,9,12,15,18,21,24,27,30]
    print $ take 10 (cycle [0,1,2])
    -- [0,1,2,0,1,2,0,1,2,0]
    print $ take 10 (repeat 3)
    -- [3,3,3,3,3,3,3,3,3,3]
    print $ replicate 10 3
    -- [3,3,3,3,3,3,3,3,3,3]

    print $ [x * 3 | x <- [1..10]]
    -- [3,6,9,12,15,18,21,24,27,30]
    print $ [x * 2 | x <- [1..10], x*2 >= 12]
    -- [12,14,16,18,20]
    print $ [x | x <- [1..50], mod x 7 == 3]
    -- [3,10,17,24,31,38,45]
    print $ [x | x <- [1..20], x /= 5, x /= 18]
    -- [1,2,3,4,6,7,8,9,10,11,12,13,14,15,16,17,19,20]

    print $ [x + y | x <- [1,2,3], y <- [10,20,30]]
    -- [11,21,31,12,22,32,13,23,33]
    print $ [x * y | x <- [1,2,3], y <- [10,20,30], x * y > 40]
    -- [60,60,90]