haskell-jp:526
From: IKEGAMI Daisuke <ikegami.da@g...>
Date: Wed, 3 Feb 2010 12:53:16 +0900
Subject: Re: [haskell-jp:525] Re: Real Wold Haskell 3章の練習問題
いけがみです。訂正ありがとう。
はい、イディオムでは foldr です。まちがえました。(3度目)
myLength :: [a] -> Int
myLength = foldr (\x y -> y + 1) 0
= foldr (const (+ 1)) 0
です。foldl と foldr の時間的計算量について気になりましたが、
以下を読んで納得しました。
http://en.wikibooks.org/wiki/Haskell/List_processing
2010年2月1日22:04 Masahiro Sakai <masahiro.sakai@g...>:
> 酒井です。
>
> From: IKEGAMI Daisuke <ikegami.da@g...>
> Date: Mon, 1 Feb 2010 10:40:13 +0900
>
>> 以下のように再度訂正してください:
>> foo :: A -> B
>> foo [] = s
>> foo (x : xs) = h x (foo xs)
>> は、A が帰納的に定義できれば「必ず」 foldl で、
>> 書き直すことができます。h は2引数です。
>> この場合は、
>> foo = foldl h s
>> となります。
>>
>> 今回は A が [a] で、リストは空リスト [] と帰納的結合(:)
>> から構成されるので、fold の idiom が使えます。
>
> foldl ではなく foldr だと思います。
>
> -- 酒井
>
515 2010-01-31 09:52 [nonaka@m... ] Real Wold Haskell 3章の練習問題 516 2010-01-31 17:09 ┣[maehrm@g... ] 517 2010-01-31 19:07 ┃┗[nonowarn@g... ] Re: [haskell-jp:516] Re: Real Wold Haskell 3章の練習問題 520 2010-01-31 20:56 ┃ ┗[maehrm@g... ] Re: Real Wold Haskell 3章の練習問題 521 2010-01-31 22:11 ┃ ┗[nonowarn@g... ] Re: [haskell-jp:520] Re: Real Wold Haskell 3章の練習問題 518 2010-01-31 19:24 ┣[nonowarn@g... ] Re: [haskell-jp:515] Real Wold Haskell 3章の練習問題 @ 519 2010-01-31 19:35 ┃┗[nonaka@m... ] 522 2010-02-01 09:16 ┗[ikegami.da@g... ] Re: [haskell-jp:515] Real Wold Haskell 3章の練習問題 523 2010-02-01 09:34 ┗[ikegami.da@g... ] 524 2010-02-01 10:40 ┗[ikegami.da@g... ] 525 2010-02-01 22:04 ┗[masahiro.sakai@g... ] Re: Real Wold Haskell 3章の練習問題 -> 526 2010-02-03 12:53 ┗[ikegami.da@g... ] Re: [haskell-jp:525] Re: Real Wold Haskell 3章の練習問題