2006-07-06
■ 真偽値
「フツケル」129頁から130頁のまとめ
- (&&)関数
- (&&) Bool -> Bool -> Bool
- x && yはxとyがともにTrueのときTrueを返します。それ以外のときはFalseを返します。
- (||)関数
- (||) :: Bool -> Bool -> Bool
- x || yはxとyのいずれかがTrueのときTrueを返します。
- サンプルプログラム
-- ファイル名:sample_bool.hs main = do print $ ("not (1 == 1)",not (1 == 1)) print $ ("not (1 == 3)",not (1 == 3)) print $ ("(10 == 10) && (20 == 20)",(10 == 10) && (20 == 20)) print $ ("(62 == 30) && (20 == 20)",(62 == 30) && (20 == 20)) print $ ("(30 == 30) && (20 == 10)",(30 == 30) && (20 == 10)) print $ ("(5 == 2 ) && (3 == 1)",(5 == 2 ) && (3 == 1)) print $ ("('a' == 'a') || ('b' == 'b')",('a' == 'a') || ('b' == 'b')) print $ ("('a' == 'a') || ('b' == 'c')",('a' == 'a') || ('b' == 'c')) print $ ("('a' == 'd') || ('b' == 'b')",('a' == 'd') || ('b' == 'b')) print $ ("('p' == 'q') || ('r' == 's')",('p' == 'q') || ('r' == 's'))
- サンプルプログラムの実行結果
d:\Development\PracticeHaskell>runghc sample_bool.hs
("not (1 == 1)",False)
("not (1 == 3)",True)
("(10 == 10) && (20 == 20)",True)
("(62 == 30) && (20 == 20)",False)
("(30 == 30) && (20 == 10)",False)
("(5 == 2 ) && (3 == 1)",False)
("('a' == 'a') || ('b' == 'b')",True)
("('a' == 'a') || ('b' == 'c')",True)
("('a' == 'd') || ('b' == 'b')",True)
("('p' == 'q') || ('r' == 's')",False)
コメントを書く
トラックバック - http://haskell.g.hatena.ne.jp/NobiNobiKota/20060706