関数の使い方メモ
動作環境
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