[Haskell-cafe] instance Enum Double considered not entirely great?

Casey McCann cam at uptoisomorphism.net
Wed Sep 21 21:11:47 CEST 2011

On Wed, Sep 21, 2011 at 2:41 PM, Brandon Allbery <allbery.b at gmail.com> wrote:
> On Wed, Sep 21, 2011 at 14:31, Casey McCann <cam at uptoisomorphism.net> wrote:
>> My thoughts are that the first interpretation is most naturally suited
>> to list range syntax, that the second would be better served by a
>> slightly different syntax to make the predicate more explicit, and
>> that the third bugs the crap out of me because it's really very useful
>> but I can't think of a concise and unambiguous syntax for it.
> Based on what you said, I'm wondering if the first gets basic fromTo syntax,
> the third gets fromThenTo syntax, and the second strikes me as a simplified
> form of list comprehension and might possibly be phrased as a cross between
> range and comprehension.  Although the most "correct" such cross has an
> ambiguity with the comma... can we still use | as the delimiter, read as
> "such that"?  ([a .. z | filter])

Hmm. I actually wrote "(..) better served by some variation on a list
comprehension" there at first before editing it to be more
non-committal. Interesting to see someone else immediately go for the
same idea. Anyway, I think this can already be expressed using GHC's
generalized list comprehensions, but the result is more verbose than I
would like for this particular very common case. My first thought on
resolving ambiguity is to rely on having something distinct following
a "..", e.g. desugaring "[a, b.. | < z]" as "takeWhile (< z) [a,
b..]", where anything ending in ".. ]" is taken to be an infinite
iterated sequence. This is only slightly more verbose than the current
form, arguably more readable, and certainly more explicit. Would need
to be more clearly specified what forms the predicate expression could
have, however.

The fromThenTo syntax doesn't seem entirely satisfactory for the third
case, because it creates ambiguity if the step size doesn't evenly
divide the range size. Having the first and last elements appear
exactly as given in the sequence and having the interval sizes be as
consistent as possible are pretty much the entire purpose here, so I'm
not sure how to reconcile that. Perhaps rounding the specified
interval to the nearest divisor? Kind of a hack, but seems to best
approximate the intent (as well as being resilient in the face of
imprecision, which is also important).

- C.

More information about the Haskell-Cafe mailing list