LoginSignup
6
6

More than 5 years have passed since last update.

Haskellの関数の動作チェック4

Last updated at Posted at 2014-06-04

関数の使い方メモ

動作環境
GHCi, version 7.6.3

concat関数

Prelude Data.List> concat ["a", "b", "c", "d"]
"abcd"
Prelude Data.List> concat [[1,5], [2,6], [3,7], [4,8]]
[1,5,2,6,3,7,4,8]

concatMap関数

Prelude Data.List> concat $ (map (\x -> show x) [1, 2, 3, 4])
"1234"
Prelude Data.List> concatMap(\x -> show x) [1,2,3,4] == concat((map(\x -> show x) [1,2,3,4]))
True

and関数

Prelude Data.List> and [True, True, False]
False
Prelude Data.List> and [True, True, True]
True
Prelude Data.List> and $ map even [2, 4, 6, 8]
True

or関数

Prelude Data.List> or [False, False, False]
False
Prelude Data.List> or [False, False, True]
True
Prelude Data.List> or $ map odd [2,4,6,8]
False
Prelude Data.List> or $ map odd [2,4,6,8,9]
True

any関数

Prelude Data.List> any (==0) [1..10]
False
Prelude Data.List> any (==0) [-1..10]
True

all関数

Prelude Data.List> all (/=0) [-1..10]
False
Prelude Data.List> all (/=0) [1..10]
True
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6