LoginSignup
5
3

More than 5 years have passed since last update.

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

Last updated at Posted at 2014-05-28

関数の使い方メモ

動作環境
GHCi, version 7.6.3

head関数

Prelude> import Data.List
Prelude Data.List> head [1..10]
1
Prelude Data.List> head [1..]
1
Prelude Data.List> head []
*** Exception: Prelude.head: empty list
Prelude Data.List> head "abc"
'a'
Prelude Data.List> head ["abc"]
"abc"

last関数

Prelude> import Data.List
Prelude Data.List> last [1..10]
10
Prelude Data.List> last [1..]
Interrupted.                  (処理中断)
Prelude Data.List> last []
*** Exception: Prelude.last: empty list
Prelude Data.List> last "abc"
'c'
Prelude Data.List> last ["abc"]
"abc"

tail関数

Prelude Data.List> tail [1..10]
[2,3,4,5,6,7,8,9,10]
Prelude Data.List> tail [1..]
[1,2,3,4,5,Interrupted.            (処理中断)
Prelude Data.List> tail "abc"
"bc"
Prelude Data.List> tail ["abc"]
[]

init関数

Prelude Data.List> init [1..10]
[1,2,3,4,5,6,7,8,9]
Prelude Data.List> tail [1..]
[1,2,3,4,5,Interrupted.            (処理中断)
Prelude Data.List> init []
*** Exception: Prelude.init: empty list
Prelude Data.List> init "abc"
"ab"
Prelude Data.List> init ["abc"]
[]

null関数

Prelude Data.List> null [1..10]
False
Prelude Data.List> null [1..]
False
Prelude Data.List> null []
True
Prelude Data.List> null ""
True
Prelude Data.List> null "abc"
False
Prelude Data.List> null ["abc"]
False
5
3
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
5
3