Subscribed unsubscribe Subscribe Subscribe

リスト操作

Haskell

Hugsにて:set +sした結果.計算結果自体は省略.

Hugs.Base> [id x | x <- [1..10000]]
(2300046 reductions, 3788974 cells, 3 garbage collections)
Hugs.Base> map id [1..100000]
(2400047 reductions, 3888975 cells, 3 garbage collections)
Hugs.Base> [1..100000] >>= return . id -- liftM id [1..100000]とおなじ.
(2900048 reductions, 4588974 cells, 4 garbage collections)
Hugs.Base> [1+x | x <- [1..100000]]
(2700046 reductions, 4688989 cells, 4 garbage collections)
Hugs.Base> map (1+) [1..100000]
(2400050 reductions, 4088992 cells, 4 garbage collections)
Hugs.Base> [1..100000] >>= return . (1+)
(2900051 reductions, 4788991 cells, 4 garbage collections)