[Haskell-beginners] truncate results depend on strict/lazy

Brandon Allbery allbery.b at gmail.com
Tue Sep 10 20:06:17 CEST 2013


On Tue, Sep 10, 2013 at 1:14 PM, Bryan Vicknair <bryanvick at gmail.com> wrote:

> This is scary though.  This is the first leak I've found in the referential
> transparency abstraction in Haskell (besides unsafePerformIO).  And the
> problem
> is, if I don't have referential transparency for 100% of pure functions,
> then I
> have to be suspicious of every one.
>

It's not quite *that* bad. Floating point is a well known source of
confusion, except to beginners; there are "why did it do this why is your
language broken waaa" posts from people discovering floating point in every
single programming language that supports them. You *cannot* 100%
accurately store numbers that can have infinite precision in a limited
address space. And the representation has its own issues, since computers
work best in powers of 2 but we work in powers of 10; numbers that are
finite in a decimal representation may be repeating infinite values in a
normalized base 2 floating representation.

(There are types such as CReal which attempt to keep arbitrary precision.
This breaks down as soon as you try to use them with transcendentals. There
is no finite *and* 100% accurate representation of pi.)

Aside from this, the only other "leaks" you're likely to ever encounter
(absent unsafePerformIO and friends) are other cases of physical hardware
being less perfect than mathematical abstraction, which is to say running
out of memory (by far the most common, but also the most amenable to
modification/correction), hardware failures, memory bit-flips, etc. At some
point, physical constraints are going to win because we can't run programs
on abstract mathematical theories, we have to run them on (however
abstracted) physical systems.

But practically, floating point is the main place where things go south;
and yes, it's generally hated in the functional programming community: no
matter what you do, real numbers are going to be a pain, and the standard
compromise known as floating point is especially frustrating because its
behavior can't be captured in a simple functional description. But floating
point is what CPUs use and have specific support for.

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130910/51747db1/attachment.htm>


More information about the Beginners mailing list