Chinaunix首页 | 论坛 | 博客
  • 博客访问: 220885
  • 博文数量: 136
  • 博客积分: 2919
  • 博客等级: 少校
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-11 09:08
文章分类

全部博文(136)

文章存档

2013年(1)

2011年(135)

我的朋友

分类: Python/Ruby

2011-06-02 15:18:19

Chapter 2: Types and Functions
p39-2: Write a function, lastButOne, that returns the element before the last.
  1. -- file ch02/lastButOne.hs
  2. lastButOne xs = if length xs == 2
  3.     then head xs
  4.     else lastButOne (tail xs)
tips: function length tells us how many elements are in a list;
      function head returns the first element of a list;
      function tail returns all but the head of a list, that is, a sub-list.
阅读(386) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~