[Haskell-cafe] How to quantify the overhead?

Daryoush Mehrtash dmehrtash at gmail.com
Wed Feb 13 23:06:33 CET 2013


Before I write the code I like to be able to quantify my expected result.
 But I am having hard time quantifying my expected result
for alternative approaches in Haskell. I would appreciate any comments
from experienced Haskell-ers on this problem:

Suppose I have a big list of integers and I like to find the first two that
add up to a number, say 10.

One approach is to put the numbers in  the map as I read them and each step
look for the 10-x of the number before going on to the next value in the
list.

Alternatively, I am trying to see if I it make sense to covert the list to
a series of computations that each is looking for the 10-x in the rest of
the list (running them  in breath first search).   I like to find out
sanity of using the Applicative/Alternative class's (<|>) operator to set
up the computation.  So each element of the list  (say x)  is recursively
converted to a computation to SearchFor (10 - x)   that is (<|>)-ed with
all previous computation until one of the computations returns the pair
that add up to 10 or all computation reach end of the list.

Does the approach make any sense?

What kind of overhead should I expect if I convert the numbers to a
computation on the list?  In one case I would have a number in a map and in
the other I would have a number in a computation over a list.  How do I
quantify the overheads?


Thanks,

Daryoush
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130213/53e9ba25/attachment-0001.htm>


More information about the Haskell-Cafe mailing list