他人のHaskell日記 RSSフィード

Haskell初心者が、リハビリがてらに「ふつける」と「入門Haskell」片手に、試行錯誤するサイト。

2009-01-04

Programming in Haskell Exercise Programming in Haskell Exercise - 他人のHaskell日記 を含むブックマーク

Chapter 1

  • Give another possible calculation for the result of double(double 2)
double(double 2)
=double(2+2)
=(2+2)+(2+2)
=(2+2)+4
=4+4
=8
  • Show that sum [x] = x for any number x
sum[x]=sum(x:[])=x+sum[]=x+0=x
  • Define a function product that produces the product of a list of numbers,and show using your definition that product[2,3,4]
product [] = 1
product (x:xs) = x * product xs
product[2,3,4]=product(2:[3,4])=2*product[3,4]=2*product(3:[4])=2*3*product[4]=2*3*prodocut(4:[])
=2*3*4*product[]=2*3*4*1=24
  • How should the definition f the function qsort be modified so that it produces a reverse sorted version of a list?
qsort[]=[]
qsort(x:xs)=qsort larger ++ [x]++ qsort smaller
            where
             smaller = [a|a<-xs,a <=x]
             larger  = [b|b<-xs,b>x]
  • What would be the effect of replacing <= by < in the definiton of qsort? Hint:consider the example qsort[2,2,3,1]

改変されたqsortをqsort'だと仮定する

qsort[2,2,3,1]=qsort [2,1] ++[2]++qsort [3]=(qsort[1]++[2]++qsort[])++[2]++(qsort[]++[3]++qsort[])
=((qsort[]++[1]++qsort[])++[2]++[])++[2]++([]++[3]++[])
=[]+[1]+[]+[2]+[]+[]+[2]+[]+[3]+[]=[1,2,2,3]
qsort'[2,2,3,1]=qsort [1] ++ [2] ++ qsort[3]=qsort[]++[1]++qsort[]++[2]++qsort[]++[3]++qsort[]
=[]++[1]++[]++[2]++[]++[3]++[]

つまり、同じ値が複数あるときは、ひとつを残して消えてしまう。

ewerunakakuzewerunakakuz2017/02/11 08:19http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

eamerzofzueamerzofzu2017/02/11 08:27http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

abiriwiyewiabiriwiyewi2017/02/11 08:39http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

gohupisgohupis2017/02/11 08:46http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

ewpoxobuewpoxobu2017/02/12 05:43http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

ukoyumuukoyumu2017/02/12 06:02http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

iviusewokagiviusewokag2017/02/13 00:58http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

evatovofutaevatovofuta2017/02/13 01:16http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

agxabahuaagxabahua2017/02/13 22:43http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

ojifokoxeojifokoxe2017/02/14 15:55http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

ecejizosuvalecejizosuval2017/02/14 16:12http://dapoxetine-onlinepriligy.net/ - dapoxetine-onlinepriligy.net.ankor <a href="http://ventolinsalbutamol-buy.org/">ventolinsalbutamol-buy.org.ankor</a> http://ventolinsalbutamolbuy.org/

usazujehnexehusazujehnexeh2017/02/15 07:24http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ivijefisivijefis2017/02/15 07:42http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

kipoufbuevovakipoufbuevova2017/02/15 23:16http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

oqitetyacoioqitetyacoi2017/02/15 23:33http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ubajufobediubajufobedi2017/02/16 15:10http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

izeyupbizeyupb2017/02/17 08:38http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ovebuyuovebuyu2017/02/17 08:57http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ifuzororipoifuzororipo2017/02/18 02:31http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ogufihealeigogufihealeig2017/02/18 21:21http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ubujihiduduhubujihiduduh2017/02/18 21:21http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ejahaafcucejahaafcuc2017/02/18 21:38http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ugesexamugesexam2017/02/18 21:38http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

itumjiduveitumjiduve2017/02/21 11:27http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ixaneomuvixaneomuv2017/02/21 11:46http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ejicapamejicapam2017/02/22 07:48http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

usjihanepusjihanep2017/02/22 08:07http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

onqherejujofonqherejujof2017/02/23 05:27http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

amulawehoamulaweho2017/02/24 03:33http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

ebexolixayebexolixay2017/02/24 03:51http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

osibakaileosibakaile2017/02/25 02:53http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/

oswuozonawoswuozonaw2017/02/26 03:10http://without-prescription-buyretin-a.net/ - without-prescription-buyretin-a.net.ankor <a href="http://doxycycline100mgbuy.com/">doxycycline100mgbuy.com.ankor</a> http://cialistadalafillowest-price.net/