Yep, the test is done by a rookie. If I get more time, I'll try to
look into testing a little more, and redo the timing (if anyone
doesn't do it firs) -- using optimizations, more runs per function and
the criterion package.
___
Haskell-Cafe mailing list
Or, when lists had a decent eliminator defined in the Prelude (just like maybe
for Maybe and either for Either):
list :: b -> (a -> [a] -> b) -> [a] -> b
list d _ [] = d
list _ f (x:xs) = f x xs
fromList = list []
we could write the alternate function like this:
alt :: [a] -> [a]
a
> From: Markus L?ll
>
> So out of curiosity i took the definitions given in this thread, and
> tried to run timing-tests.
> Here's what I ran:
>> ghc -prof -auto-all -o Test Test.h
>> Test +RTS -p
> and then looked in the Test.prof file.
I think this is a poor approach for timing tests, for two r
On Wed, Jun 09, 2010 at 11:47:32PM +0300, Markus Läll wrote:
> As the function doing (x:_:rest) pattern-matching was the fastest I
> extended the idea from that to (x1:_:x2: ... x10:_:rest), but skipping
> from 5 to 10, where all steps showed a small increase in performance.
>
> So a question: whe
Markus Läll wrote:
> So out of curiosity i took the definitions given in this thread, and
> tried to run timing-tests.
Nice!
> Any comments? (besides -O2 ;-) -- I remembered it too late and didn't
> want to restart...
Oh, could you please run that again with -O2?
My entry dearly depends on it
Forgot the file -- here it is:
module Main where
import Data.Either (rights)
import Data.Function (fix)
test f = putStr $ show $ last $ f $ replicate 1000 (1 :: Int)
main = test matchPattern4
-- 1. zipNums
-- 2. matchPattern
-- 3. zipBoolCycle
-- 4. iterDrop
-- 5. zipBoolCycle2
-- 6. consum
So out of curiosity i took the definitions given in this thread, and
tried to run timing-tests.
Here's what I ran:
> ghc -prof -auto-all -o Test Test.h
> Test +RTS -p
and then looked in the Test.prof file.
All tests I ran from 3 to 10 times (depending on how sure I wanted to
be), so the results a
OK, here's mine:
f as = [ x | (True,x) <- zip (cycle [True, False]) as ]
-md
begin R J quotation:
>
> What's the cleanest definition for a function f :: [a] -> [a] that takes a
> list and returns the same list, with alternate items removed? e.g., f [0, 1,
> 2, 3, 4, 5] = [1,3,5]?
>
Christopher Done wrote:
> Can't forget fix in a game of code golf!
>
>> (fix $ \f (x:_: xs) -> x : f xs) [1..]
> => [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,4...
Ho, good shot! It only works for infinite lists, though:
Prelude> (fix $ \f (x:_: xs) -> x : f xs) [1..10]
[1,3,5,7,9
>
> It only works for infinite lists, though
>
you wanted it :)
(fix $ \f xs -> case xs of { (x:_: xs) -> x : f xs; _ -> [] }) [1..10]
= [1,3,5,7,9]
here you go :)
2010/6/8 Yitzchak Gale
> Christopher Done wrote:
> > Can't forget fix in a game of code golf!
> >
> >> (fix $ \f (x:_: xs) -> x :
El dom, 06-06-2010 a las 14:46 +, R J escribió:
> What's the cleanest definition for a function f :: [a] -> [a] that
> takes a list and returns the same list, with alternate items removed?
> e.g., f [0, 1, 2, 3, 4, 5] = [1,3,5]?
adding another suggestion:
import Data.Either(rights)
f = righ
Hello
The regular list functionals - map, zip, foldl, foldr, filter, etc. -
all process the input list at "speed 1" - i.e. one element at a time.
As Ozgur Akgun has shown - consuming the list at "speed 2" gives a
very pleasant implementation - algorithmically:
"consume at speed 2, produce the new
On 8 June 2010 15:13, Jürgen Doser wrote:
> El dom, 06-06-2010 a las 14:46 +, R J escribió:
>> What's the cleanest definition for a function f :: [a] -> [a] that
>> takes a list and returns the same list, with alternate items removed?
>> e.g., f [0, 1, 2, 3, 4, 5] = [1,3,5]?
>
> adding anothe
Yes, this was an old draft I accidentally sent out.
My post higher up the thread is correct. :)
On Tuesday, June 8, 2010, Ozgur Akgun wrote:
> if we add 'a' to the definition of this function, (to make it work), the type
> of it turns out to be: [a] -> [(a, Bool)]
>
> you might have forgotten t
2010/6/6 R J :
> What's the cleanest definition for a function f :: [a] -> [a] that takes a
> list and returns the same list, with alternate items removed? e.g., f [0,
> 1, 2, 3, 4, 5] = [1,3,5]?
f x = [y | (True, y) <- zip (cycle [False, True]) x]
___
And for a few more lines of codes, you get a more flexible solution:
data Consume = Take | Skip
consumeBy :: [Consume] -> [a] -> [a]
consumeBy [] _ = []
consumeBy _[] = []
consumeBy (tOrS:takesAndSkips) (x:xs) = case tOrS of
f :: [a] -> [a]
f = filter snd $ zip a (cycle [True, False])
On Monday, June 7, 2010, Ozgur Akgun wrote:
> or, since you don't need to give a name to the second element of the list:
>
> f :: [a] -> [a]
> f (x:_:xs) = x : f xsf x = x
>
>
>
>
> On 7 June 2010 20:11, Ozgur Akgun wrote:
>
> i think
if we add 'a' to the definition of this function, (to make it work), the
type of it turns out to be: [a] -> [(a, Bool)]
you might have forgotten the "map fst $" part.
Best,
On 8 June 2010 14:51, Bill Atkins wrote:
> f :: [a] -> [a]
> f = filter snd $ zip a (cycle [True, False])
>
> On Monday,
Can't forget fix in a game of code golf!
> (fix $ \f (x:_: xs) -> x : f xs) [1..]
=> [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,4...
2010/6/8 Yitzchak Gale :
> R J wrote:
>> What's the cleanest definition for a function f :: [a] -> [a] that takes a
>> list and returns the same lis
R J wrote:
> What's the cleanest definition for a function f :: [a] -> [a] that takes a
> list and returns the same list, with alternate items removed? e.g., f [0,
> 1, 2, 3, 4, 5] = [1,3,5]?
f = map head . takeWhile (not . null) . iterate (drop 2) . drop 1
Regards,
Yitz
alts :: [a] -> [a]
alts xs = map fst . filter snd $ zip xs (cycle [False, True])
Prelude> alts [0, 1..5]
[1,3, 5]
On Sunday Jun 6, 2010, at 10:46 AM, R J wrote:
> What's the cleanest definition for a function f :: [a] -> [a] that takes a
> list and returns the same list, with alternate items re
or, since you don't need to give a name to the second element of the list:
f :: [a] -> [a]
f (x:_:xs) = x : f xs
f x = x
On 7 June 2010 20:11, Ozgur Akgun wrote:
> i think explicit recursion is quite clean?
>
>
> f :: [a] -> [a]
> f (x:y:zs) = x : f zs
> f x = x
>
>
>
>
> On 7 June 2010 19:4
i think explicit recursion is quite clean?
f :: [a] -> [a]
f (x:y:zs) = x : f zs
f x = x
On 7 June 2010 19:42, Thomas Hartman wrote:
> maybe this?
>
> map snd . filter (odd . fst) . zip [1,2..] $ [1,2,3,4,5]
>
> 2010/6/6 R J :
> > What's the cleanest definition for a function f :: [a] -> [a]
maybe this?
map snd . filter (odd . fst) . zip [1,2..] $ [1,2,3,4,5]
2010/6/6 R J :
> What's the cleanest definition for a function f :: [a] -> [a] that takes a
> list and returns the same list, with alternate items removed? e.g., f [0,
> 1, 2, 3, 4, 5] = [1,3,5]?
>
> ___
What's the cleanest definition for a function f :: [a] -> [a] that takes a list
and returns the same list, with alternate items removed? e.g., f [0, 1, 2, 3,
4, 5] = [1,3,5]?
_
The New Bus
25 matches
Mail list logo