Haskell is lazy evaluation!
Prelude> :show bindings Prelude> let x = 2010 Prelude> :show bindings x :: Integer = _ Prelude> x 2010 Prelude> :show bindings it :: Integer = 2010 x :: Integer = 2010 Prelude>
Exercises Answers:
3: The words function counts the number of words in a string. Modify the WC.hs example to count the number of words in a file.
main = interact wordCount
where wordCount input = show (length (words input)) ++ "\n"
4: Modify the WC.hs example again, to print the number of characters in a file.
main = interact wordCount
where wordCount input = show (length input) ++ "\n"
Useful command
:set +t
:unset +t
:m Data.Radio
it
Haskell懒惰求值与练习解答
本文介绍Haskell中的懒惰求值概念,并通过示例展示其工作原理。此外,还提供了两个关于文件处理的练习题解答,分别演示了如何计算文件中的单词数及字符数。
149

被折叠的 条评论
为什么被折叠?



