[Haskell-cafe] Re: [Haskell-beginners] Problem "grouping" a list

2010-11-24 Thread Aai
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)

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-19 Thread Aai
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]

Re: [Haskell-cafe] convert a list of booleans into Word*

2009-09-30 Thread Aai
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

Re: [Haskell-cafe] convert a list of booleans into Word*

2009-09-30 Thread Aai
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

Re: [Haskell-cafe] convert a list of booleans into Word*

2009-09-30 Thread Aai
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

Re: [Haskell-cafe] Looking for pointfree version

2009-02-09 Thread Aai
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

Re: [Haskell-cafe] Re: Timing difference

2008-12-25 Thread Aai
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/

Re: [Haskell-cafe] Timing difference

2008-12-25 Thread Aai
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:/

[Haskell-cafe] Timing difference

2008-12-25 Thread Aai
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