I'm pretty confident that this will be more efficient than my colleague's SAS code, as he was comparing each record to every other record (giving n (n-1) comparisons). It seems like this, in the worst case where everything is on promotion at distinct times, will compare the first record to (n-1)
Hi, all.
I have an exceedingly simple problem to address, and am wondering if there are
relatively straightforward ways to improve the efficiency of my solution.
The task is simply to look at a lengthy list of stock keeping units (SKUs -- what
retailers call individual items), stores, dates t
| powerset :: [a] -> [[a]]
| powerset [] = [[]]
| powerset (x:xs) = xss ++ map (x:) xss
| where xss = powerset xs
Elegant as it is, this program causes a serious space leak.
(In fact, it is often cited as an example of why functional
programming language implementations might choos
Graham Klyne wrote:
At 15:08 04/06/03 +0100, Liyang HU wrote:
A key point is to try and think of how you can relate one case of the
problem to a simpler instance of the same problem, rather than
tackling it
head on.
I think that's a good idea to hang on to. Sometimes easier to say than
to do,
Ahh... I see now (thanks). This advice (in the documentation for
System.IO.Error.ioError) threw me:
"The ioError variant should be used in preference to throw to raise an
exception within the IO monad because it guarantees ordering with respect to
other IO operations, whereas throw does not."
Aft
G'day all.
On Wed, Jun 04, 2003 at 02:00:08PM +0100, Keith Wansbrough wrote:
> This formulation is particularly nice because in memory, you *share*
> all of the lists from the previous iteration, rather than making
> copies.
[...]
> Notice all the sharing - this is a very efficient representation
On Wed, 4 Jun 2003 15:08:44 +0100
Liyang HU <[EMAIL PROTECTED]> wrote:
> Hi Graham,
>
> On Wed, Jun 04, 2003 at 12:08:38PM +0100, Graham Klyne wrote:
> > I thought this may be a useful exercise to see how well I'm picking
> > up on functional programming idioms, so I offer the following for
> > c
Malcolm Wallace wrote:
> > > > foreign import ccall "math.h signgam" signgamC :: IO Int
> >
> > signgam is an "int" variable, but this assumes that it is a function
> > of type "int signgam(void)".
> >
> > Write a C wrapper "int get_signgam(void) { return signgam; }" and
> > import that.
>
> O
At 14:00 04/06/03 +0100, Keith Wansbrough wrote:
Looks fine, but you're right - the use of "combinations" is
inefficient. It's better to iterate over the elements, rather than
the length. Then as you add each element, you consider all the sets
you have so far, and either add the new element to ea
At 15:08 04/06/03 +0100, Liyang HU wrote:
A key point is to try and think of how you can relate one case of the
problem to a simpler instance of the same problem, rather than tackling it
head on.
I think that's a good idea to hang on to. Sometimes easier to say than to
do, it seems.
Thanks,
#g
Malcolm Wallace wrote:
> > > > foreign import ccall "math.h signgam" signgamC :: IO Int
> >
> > signgam is an "int" variable, but this assumes that it is a function
> > of type "int signgam(void)".
> >
> > Write a C wrapper "int get_signgam(void) { return signgam; }" and
> > import that.
>
> Or al
In Control.Exception, there's:
> data Exception = ...
>| DynException Dynamic
>| ...
and
> throwIO :: Exception -> IO a
so, what you want is probably something like:
> if rc < 0
> then throwIO (DynException (toDyn ("Err", rc)))
> else ...
and then when you
(I know I'm asking some noddy questions, but hey, that's what this list is
for...)
How do I create IOError exceptions? System.IO.Error has two functions that
create IOErrors: userError and mkIOError. However, both of them take a
String (I assume containing a description of the problem), and mkIOEr
Dnia śro 4. czerwca 2003 14:16, Bayley, Alistair napisał:
> Is alloca the idiomatic technique when you want to create a pointer to a
> pointer? Or are there other ways?
It's an idiomatic technique for creating a temporary C object whose lifetime
is explicit. You could use malloc, but then you ha
Hi Graham,
On Wed, Jun 04, 2003 at 12:08:38PM +0100, Graham Klyne wrote:
> I thought this may be a useful exercise to see how well I'm picking up on
> functional programming idioms, so I offer the following for comment:
> foldl (++) [] [ combinations n as | n <- intRange 1 (length as) ]
By
15 matches
Mail list logo