[Haskell-cafe] instance Enum Double considered not entirely great?
Jake McArthur
jake.mcarthur at gmail.com
Fri Sep 23 02:05:17 CEST 2011
On Thu, Sep 22, 2011 at 7:02 PM, Richard O'Keefe <ok at cs.otago.ac.nz> wrote:
>
> On 21/09/2011, at 11:42 PM, Jake McArthur wrote:
>> With fixed point numbers, it makes sense to have an Enum instance.
>
> What is the use case?
I'm not quite sure how to answer this. I'm speaking in a fairly general sense.
> But that does not mean you want to pretend they are integers,
> and having an Enum instance is basically about pretending to be
> integers.
Even if you are trying to fit your explanation of Enum to the existing
behavior, I disagree because ([0.0, 0.1 .. 1.0] :: Double) is
inconsistent with that explanation. I think the only reasonable
characterization of Enum's current behavior is that it provides some
way to take same-sized steps through a range of values, and that's
about all it promises.
> There are at least two defensible understandings of what a fixed point
> number means. One is appropriate for finance, which is that the numbers
> are exact rational numbers of the form m/b^n for integer m, n and
> integer b > 1. [...]
>
> The other understanding is appropriate for engineering (think of ADCs and
> DACs) and is that the numbers are approximate. That seems to be what you
> have in mind.
I have both in mind, although it's actually the former style of fixed
point arithmetic that I'm more interested in (and I disagree that
there is such a distinction between finance and engineering...
precision is very important in engineering). The former is not as
difficult as you have characterized it, and my fixed-point package
provides an interface similar to (although still different from) what
you described. Care is taken to make the precision clear in the types
and documentation. There isn't currently much choice for rounding
methods for division, but this is something I intend to correct in the
future. Evan also pointed out some bugs and other lacking
functionality which I intend to address this weekend. Fixed point
arithmetic is really only useful as an approximation when you have a
statically bounded range of values to work in; otherwise, you might as
well just use floating point arithmetic anyway.
> Let's face it, Enum badly needs some revision. [...]
Agreed.
> As things c
I think your email got cut off here.
- Jake
More information about the Haskell-Cafe
mailing list