[Haskell-cafe] Re: Ultra-newbie Question
Henrique Becker
henriquebecker91 at gmail.com
Mon Sep 20 20:45:23 EDT 2010
Thanks, It's my first post.
If you not import Prelude is more clear (N. is horrible):
import Prelude ((-), Integral)
import Data.Number.Nat (drop, length, toNat)
lastN :: Integral b => b -> [a] -> [a]
lastN n xs = drop (length xs - n') xs
where n' = toNat n
P.S.: You benchmarked? I didn't...
2010/9/20, Luke Palmer <lrpalmer at gmail.com>:
> On Mon, Sep 20, 2010 at 5:11 PM, Luke Palmer <lrpalmer at gmail.com> wrote:
>> On Sun, Sep 19, 2010 at 5:01 PM, Henrique Becker
>> <henriquebecker91 at gmail.com> wrote:
>>> Why not?
>>>
>>> import Data.Number.Nat as N
>>>
>>> lastN :: Integral b => b -> [a] -> [a]
>>> lastN n xs = N.drop (N.length xs - n') xs
>>> where n' = N.toNat n
>>
>> Wow. That is gorgeous! I think it's basically the same idea as my
>> "zipWith" implementation, but it is so much clearer here. Thanks :-)
>
> Er forget that zipWith comment. It is quite unlike that. But it is
> still beautiful and efficient.
>
More information about the Haskell-Cafe
mailing list