newbie conceptual question [from haskell list]

D. Tweed tweed@compsci.bristol.ac.uk
Thu, 26 Jul 2001 11:55:01 +0100 (BST)


On Thu, 26 Jul 2001, Frank Atanassow wrote:
> also safety, and "theorems for free". Then there are other properties
which
> are obvious (to a programmer) in a Haskell program which get buried in
the
> equivalent C(++) program, e.g., that every member of a data structure is
> traversed in a fold ("no early exits"). Many of these things hinge on
the
> typing of a program, which is inferred and checked for you, so there is
less
> of a burden on conscientious programmers.

I'm being terribly unfair here; this was probably just a simple slip when
writing a hurried e-mail but if you mean what I think you mean about the
fold:

undefd = undefd

f y x|y=='a' = "finished"
     |otherwise = y:x

g xs = foldr f "" xs

Main> g ('a':undefd)
"finished"

shows that folds can exit early; if it didn't it'd black hole forever.

___cheers,_dave________________________________________________________
www.cs.bris.ac.uk/~tweed/pi.htm |tweed's law:  however many computers
email: tweed@cs.bris.ac.uk      |   you have, half your time is spent
work tel: (0117) 954-5250       |   waiting for compilations to finish.