top page > computer > haskell > web_lecture > for_programmer > list_fun_defs.html
更新日:
文責: 重城良国

リストを扱う関数の定義について

はじめに

リストを扱う標準的な関数の定義を見ていく。生の再帰による定義と、いくつかは関数foldr、foldl、unfoldrを使った定義を見る。

動作

% ghci
Prelude> :m Data.Char
Prelude Data.Char> toUpper `map` "Haskell"
"HASKELL"
Prelude Data.Char> filter isLower "Capes"
"apes"
Prelude Data.Char> partition isLower "Capes"
("C", "apes")
Prelude Data.Char> take 4 "monkey"
"monk"
Prelude Data.Char> drop 3 "monkey"
"key"
Prelude Data.Char> splitAt 3 "monkey"
("mon", "key")
Prelude Data.Char> takeWhile isLower "takeWhile"
"take"
Prelude Data.Char> dropWhile isLower "takeWhile"
"While"
Prelude Data.Char> span isLower "takeWhile"
("take", "While")
Prelude Data.Char> zip [0 ..] "hello"
[(0,'h'),(1,'e'),(2,'l'),(3,'l'),(4,'o')]
Prelude Data.Char> zipWith (+) [2, 5, 10] [5, 9, 7, 8]
[7,14,17]
Prelude Data.Char> unzip [(4, 'a'), (4, 'b'), (9, 'c'), (2, 'd')]
([4,4,9,2],"abcd")
Prelude Data.Char> "Yoshikuni" ++ "Jujo"
"YoshikuniJujo"
Prelude Data.Char> concat ["Haskell", "Brooks", "Curry"]
"HaskellBrooksCurry"
Prelude Data.Char> reverse "gateman"
"nametag"
Prelude Data.Char> take 32 $ repeat 'a'
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Prelude Data.Char> replicate 32 'a'
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Prelude Data.Char> take 32 $ cycle "Happy"
"HappyHappyHappyHappyHappyHappyHa"

「フィボナッチ数列」へもどる 「関数map」へ

正当なCSSです! HTML5 Powered with CSS3 / styling, and Semantics