I don't know what this tuple is representing, but if you want to group you'll
have to specify on 'what':
- the tuple,
- the fst or
- the snd
Here's a possibility with grouping on the fst
import Data.List
import Data.Ord
import Data.Function
groupAtoms ::
(Float -> Bool)
-> [(Float,Integer)
I like this one!
Here's a variant using fold:
lastk :: Int -> [a] -> [a]
lastk k xs = foldl' (const.tail) xs (drop k xs)
or point free:
lastk = ap (foldl' (const. tail)). drop
Hallo Luke Palmer, je schreef op 18-09-10 22:42:
> I think this is O(n) time, O(1) space (!).
>
> lastk :: Int -> [a]
Very fast for long boolean lists by using a strict foldl and reversing
the input:
bsToInt :: [Bool] -> Integer
bsToInt = foldl' ((.fromIntegral.fromEnum).(+).join(+)) 0. reverse
Try this:
(>1) $ bsToInt $ take 10 $ cycle [True,True,False,True,True,False,True]
>> bitsToInt :: [Bool] -> Int
Sorry, msb rigthmost
> Here's another approach for Bool lists with msb leftmost:
>
> bitsToInt :: [Bool] -> Integer
> bitsToInt = foldr((.(flip shiftL 1)).(+)) 0. map (fromIntegral.fromEnum)
>
>
>
> Hallo paul.brau...@loria.fr, je schreef op 30-09-09 11:18:
>
>> Hello,
>>
>> I haven't found a f
Here's another approach for Bool lists with msb leftmost:
bitsToInt :: [Bool] -> Integer
bitsToInt = foldr((.(flip shiftL 1)).(+)) 0. map (fromIntegral.fromEnum)
Hallo paul.brau...@loria.fr, je schreef op 30-09-09 11:18:
> Hello,
>
> I haven't found a function in hackage or in the standard libr
Rewriting it to:
concatMap ($ p)[downPar , downNew , downTrans ]
gives:
($ p) =<< [downPar, downNew, downTrans]
didn't check though!
=@@i
Edsko de Vries schreef:
> Hi,
>
> Is there a nice way to write
>
> down :: Focus -> [Focus]
> down p = concat [downPar p, downNew p, downTrans p]
>
> in
faster than interpreted point free: not world shaking.
May be there's a compile optimization that I'm not aware of.
Thanks
=@@i
Max Vasin schreef:
> Aai пишет:
>> Hi Bulat,
>>
>> That I (can) understand, but of course the main question is: is point
>> free in (some/
Hi Bulat,
That I (can) understand, but of course the main question is: is point
free in (some/several/all) cases faster than the more readable lambda
construction? That's to say when executed in GHCi. I noticed this
behavior before (pity I haven't other examples at hand). In prog. lang.
J ( http:/
Programming for Rosetta Codes task
http://www.rosettacode.org/wiki/Probabilistic_Choice I observed a
remarkable (that's to say: for me) difference in timing using lambda
function in the one case and point free in the other. Timing was
measured in GHCi. Compiled there's no difference!
Using lambda