第四章内容比第三章多了不少,学习进度明显慢了许多。
在Haskell里,遍历元素,并加以操作的方式与命令式编程感觉真是差太多了,很多时候,你明明知道算法该怎么做,但是就是在Haskell里不知道该如何表达。不怕出丑的说,如何求一组数中的最小值,这种简单东西都把我卡了不少时间,最后瞟了一眼Prelude里的minimum函数实现,我擦,这么简单……因为很难从以前的习惯里解脱出来,想不到如何在haskell这个全是递归的环境里设一个中间变量进行保存临时值。
断断续续用业余时间做了几题练习。咳,放上一部分做个记录,之后再补全。
-- 1. Write your own “safe” definitions of the standard partial list functions, but make sure that yours never fail. As a hint, you might want to consider using the following types.
-- 2.Write a function splitWith that acts similarly to words, but takes a predicate and a list of any type, and splits its input list on every element for which the predicate returns False.
--Using the command framework from the section called “A simple command line framework”, write a program that prints the first word of each line of its input.
--Write a program that transposes the text in a file. For instance, it should convert "hello/nworld/n" to "hw/neo/nlr/nll/nod/n".