[Haskell-beginners] Fwd: tower hanoi problem

Joel Neely joel.neely at gmail.com
Sun Feb 22 13:49:11 UTC 2015


Nice!

Just out of curiosity...

I have no trouble accepting that the zipWith3 approach is more idiomatic,
but it doesn't appear (to my eye) significantly shorter or significantly
more obvious. So are the tradeoffs primarily cultural, or is there another
issue that I'm missing?

Thanks,
-jn-

On Sat, Feb 21, 2015 at 12:04 PM, Chaddaï Fouché <chaddai.fouche at gmail.com>
wrote:

> On Sat, Feb 21, 2015 at 4:50 PM, Joel Neely <joel.neely at gmail.com> wrote:
>
>>
>> smooth :: Fractional n => [n] -> [n]
>> smooth (a:z@(b:c:_)) = (a + b + c) / 3 : smooth z
>> smooth _             = []
>>
>>
>>
> In Haskell, I would write this with higher-order functions though :
>
> smooth xs = zipWith3 (\a b c -> (a+b+c)/3) xs (drop 1 xs) (drop 2 xs)
>
> --
> Jedaï
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>


-- 
Beauty of style and harmony and grace and good rhythm depend on simplicity.
- Plato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150222/9ecf494d/attachment.html>


More information about the Beginners mailing list