[Haskell-cafe] Re: pi

ChrisK haskell at list.mightyreason.com
Wed Oct 10 05:58:51 EDT 2007

jerzy.karczmarczuk at info.unicaen.fr wrote:
> Yitzchak Gale writes:
>> Dan Piponi wrote:
>>> The reusability of Num varies inversely with how many
>>> assumptions you make about it.
>> A default implementation of pi would only increase usability,
>> not decrease it.
> Suppose I believe you. (Actually, I am afraid, I have doubts.)
> Can you provide some examples of this "increased usability"?
> If possible, with a *relevant* context, which shows that PI should belong
> by default to the class Floating (whatever we mean by that...)
> Somehow I do not only think that the default implementation would be good
> for nothing, but that putting PI into Floating as a class member, serves
> nobody.

Putting 'pi' in the same class as the trigonometric functions is good design.

> I would be happy to learn that I am mistaken, but if it is just
> to save 5 seconds of a person who wants to pass smoothly between floating
> numbers of single and double precision...
> Jerzy Karczmarczuk

Moving smoothly from single to double precision was much of the motivation to
invent a mechanism like type classes in the first place.

There are two things in Floating, the power function (**) [ and sqrt ] and the
transcendental functions (trig functions,exp and log, and constant pi).

Floating could be spit into two classes, one for the power and one for the
transcendental functions.  And I would bet that some of the custom mathematical
prelude replacements do this.

If you do not want 'pi' in a class named Floating then you have to move all the
transcendental stuff with it.

If you do not want 'pi' in any class, then you cannot reasonably put any of the
transcendental functions in a class.  This would really degrade the API.


More information about the Haskell-Cafe mailing list