Programming in Haskell exercises (1)

Working on exercises of Chapter 1 Introduction

拇指 muzhi.com
Analytics Vidhya
Published in
3 min readDec 30, 2019

--

code tested on this mac

Change terminal prompt and ghci prompt. Let ghci support multiple lines.

  1. Give another possible calculation for the result of double (double 2).

2. Show that sum [x] = x for any number x.

3. Define a function product that produces the product fo a list of numbers, and show using your definition that product [2,3,4] = 24.

Another way to do multi line is using :{ and :}, like this:

4. How should the definition of the function qsort b modified so that it produces a reverse sorted version of a list?

5. What would be the effect of replacing by < in the original definition of qsort? Hint: consider the example qsort [2,2,3,1,1].

There is no duplication in the result list.

--

--