[Haskell-cafe] [m..n] question

Richard A. O'Keefe ok at cs.otago.ac.nz
Sun Sep 21 20:31:02 EDT 2008

Erlang's equivalent of [m..n] is lists:seq(M, N),
which is currently defined to raise an exception when N < M.
In particular, lists:seq(1, N) returns a list of length N
when N > 0, but not when N = 0.
I'm currently arguing that lists:seq(1, 0) should be [],
not an exception.  Oddly enough, I'm being beaten over the
head with Haskell, of all things.

In Haskell,
"The sequence enumFromTo e1 e3 is the list [e1,e1+1,e1+2,...e3].
  The list is empty if e1 > e3."

It is being claimed that the reason for this is that "exceptions
are problematic" in Hasell, so the Haskell designers went out of
their way to make this function total whether it made sense or not.

I am currently suggesting that it's to keep the specification
(for integers) simple:
"[m..n] is the set of integers x such that m<=x<=n,
  listed in ascending order".
There's also the nice equivalence between
[m..n] and takeWhile (<= n) [m..].
Unfortunately, no such "abstract" characterisation of [m..n] is
mentioned in the report, and the takeWhile connection is
inferred from numericEnumFromTo.

Does anyone remember why the definition of enumFromTo is the way it is?

If stupidity were a crime, who'd 'scape hanging?

More information about the Haskell-Cafe mailing list