[Haskell-cafe] Re: pi

David Roundy droundy at darcs.net
Wed Oct 10 17:17:13 EDT 2007


On Wed, Oct 10, 2007 at 10:52:36PM +0200, jerzy.karczmarczuk at info.unicaen.fr wrote:
> >... Where is the abomination here?
> 
> Having THREE different power operators, one as a class member, others as
> normal functions. Do you think this is methodologically sane? 

It's a bit odd, but I prefer it to having one hyper-overloaded power
operator that you hope will be efficient for small integer arguments.  I
suppose if I designed the hierarchy I'd probably have two power operators,
both as class members.  But then again, this would slow down some code, and
it'd be nice to avoid that.

> >Would you also prefer to eliminate sqrt and log? We've been using these
> >functions for years (in other languages)... I think it's quite sensible, 
> >for instance, that passing a negative number as the first argument of 
> >(**) with the second argument non-integer leads to a NaN.
> 
> As you wish. But, since this is an overloaded class member, making it
> sensitive to the exponent being integer or not, is awkward. And perhaps
> I would *like* to see the result being complex, non NaN?
> Oh, you will say that it would break the typing. NaN also does it, in
> a sense. And this suggests that the type a->a->a is perhaps a wrong choice.
> Of course, this implies a similar criticism of log and sqrt...
> (One of my friends embeds the results of his functions in a generalization
> of Maybe [with different Nothings for different disasters], and a numerical
> result, if available, is always sound.) 

There are certainly other options, but the only fast option that I'm aware
of is to use IEEE floating point arithmetic (or rather, the approximation
thereof which is provided by modern CPUs).  It's awkward treating things
specially based on whether the argument is an integer, but also provides a
rather dramatic optimization for those who don't know it's better to use
(^) or (^^).
-- 
David Roundy
Department of Physics
Oregon State University


More information about the Haskell-Cafe mailing list