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

はわわーっ

はわわわわっ

リスト使うよ

haskell

haskellのリストの入門的ななにか

main = do
    print $ [1,2,3] ++ [4,5,6]
    -- [1,2,3,4,5,6]
    print $ [1,2,3] ++ [4]
    -- [1,2,3,4]
    print $ 0:[1,2,3]
    -- [0,1,2,3]
    print $ [1,2,3,4] !! 0
    -- 1
    print $ [1,2,3,4] !! 3
    -- 4
    print $ [[1,2,3],[4,5,6],[7,8,9]]
    -- [[1,2,3],[4,5,6],[7,8,9]]
    print $ [[0],[1,2],[3,4,5,6]] ++ [[7,8,9]]
    -- [[0],[1,2],[3,4,5,6],[7,8,9]]
    print $ [[0],[1,2],[3,4,5,6]] !! 1
    -- [1,2]

    print $ head [1,2,3,4,5]
    -- 1
    print $ tail [1,2,3,4,5]
    -- [2,3,4,5]
    print $ last [1,2,3,4,5]
    -- 5
    print $ init [1,2,3,4,5]
    -- [1,2,3,4]
    print $ length [1,2,3,4,5]
    -- 5
    print $ null [1,2,3,4,5]
    -- False
    print $ null []
    -- True

    print $ take 3 [1,2,3,4,5]
    -- [1,2,3]
    print $ take 10 [1,2,3,4,5]
    -- [1,2,3,4,5]
    print $ take 0 [1,2,3,4,5]
    -- []

    print $ drop 3 [1,2,3,4,5]
    -- [4,5]
    print $ drop 10 [1,2,3,4,5]
    -- []
    print $ drop 0 [1,2,3,4,5]
    -- [1,2,3,4,5]

    print $ maximum [1,2,3,4,5]
    -- 5
    print $ minimum [1,2,3,4,5]
    -- 1
    print $ sum [1,2,3,4,5]
    -- 15
    print $ product [1,2,3,4,5]
    -- 120

    print $ elem 3 [1,2,3,4,5]
    -- True
    print $ elem 10 [1,2,3,4,5]
    -- False