[Haskell-beginners] How to process a list that contains "undefined" values?
Brandon Allbery
allbery.b at gmail.com
Sat Jul 2 17:04:37 CEST 2011
On Sat, Jul 2, 2011 at 10:09, Costello, Roger L. <costello at mitre.org> wrote:
> How would you find the maximum value in this list:
>
> [undefined, 10, undefined, 20]
>
> Is it bad practice to create lists that contain undefined values?
"undefined" is not "null"; "Nothing" is. "undefined" represents a
computation that never produces a result: an infinite loop or a
crash. Some but by far not all of these can
be characterized at runtime and turned into exceptions. (The literal
Prelude.undefined explicitly throws an exception, but could just as
well be "let x = x in x" and let the ghc runtime catch it.)
The type tells you this right out, by the way:
> undefined :: a
What can you do with a "value" that can be any conceivable type, and
about which nothing else can be said? It has no handles, no behavior;
the only possible interpretation is that it's not a value at all.
--
brandon s allbery allbery.b at gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
More information about the Beginners
mailing list