[Haskell-cafe] How to take a minimum sub list that only contain certain number of elements of certain type?
Richard O'Keefe
ok at cs.otago.ac.nz
Wed Sep 26 02:17:56 CEST 2012
On 26/09/2012, at 5:56 AM, Gwern Branwen wrote:
> On Tue, Sep 25, 2012 at 1:42 PM, Rishabh Jain <rishabh11 at live.com> wrote:
>> f x 0 = []
>> f (x:xs) y | x `mod` 2 == 0 = x : (f xs y) | otherwise = x : (f xs (y-1))
>>
>>> f [0..] 4
>>> [0,1,2,3,4,5,6,7]
>
> Tsk, tsk. So ugly. How's this:
>
>> let f x = take x . filter odd
Wrong. The original poster gave an explicit example
in which even elements were *retained* in the output,
they just weren't *counted*.
More information about the Haskell-Cafe
mailing list