Wed, 26 Jan 2000 16:16:39 +0100 (MET), Ch. A. Herrmann 
<[EMAIL PROTECTED]> pisze:

> the problem with an unnecessary restriction is that it complicates
> reasoning about the program.
> Instead of
> 
>    xs
>  = { take/drop-law }
>    take (n-m) xs ++ drop (n-m) xs
> 
> you have to write, e.g.:
> 
>    xs
>  = { restricted take/drop-law }
>    if n<m then undefined else take (n-m) xs ++ drop (n-m) xs

Many properties are broken anyway in presence of negative arguments
to take and drop irrelevantly to what they do in that case (if we want
to keep the current definition for nonnegative arguments of course).

drop n . drop m = drop (n+m)          -- try n = -1, m = 1
take n . drop m = drop m . take (n+m) -- try n = 1, m = -1
-- The second could be valid only when drop (-1) = const [],
-- which does not make sense at all.

My preference is still (B). (A) is not *very* bad, but should really
replicate (-7) "foo" be []?

> If using a natural type, people will insist on having a partial
> minus operation. How should the compiler check that this operation
> is well-defined? If the compiler can't, why have this type at all
> if the integers are available?

This is not a valid argument, because it requires adding the result
of 1/0 to the type of rationals, and it says that you must use complex
numbers instead of reals because reals don't have square root defined
on all arguments... Or I can't see the difference.

I don't say that we need the natural type in Haskell. It is so close
to integers (only half of values is wasted) and it is so common to
convert between the two, that it's not worth the duplication and
confusion. I certainly would not want to have to convert the result
of length from natural to integer when I want to compute a signed
difference between two lengths!

> In general, the larger a domain of an operation is, the simpler
> is the handling. If, i.e., a division by zero produces a value
> "div by zero" instead of an error message, subsequent operations
> may deal with it and the entire computation can succeed.

But the larger a domain of an operation is, the larger class of errors
can pass unnoticed in the first place. Especially when the "natural
definition" does not assign any meaning to particular arguments, e.g.
head [].

-- 
 __("<    Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
 \__/              GCS/M d- s+:-- a22 C+++$ UL++>++++$ P+++ L++>++++$ E-
  ^^                  W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK                  5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-

Reply via email to