... It's very hard to debug a large program when you
can randomly get messages like "*** Exception: Prelude.head: empty
list" and have no idea where they came from.
As a purely pragmatic suggestion: don't use head, fromJust, last, or any
other function that is likely to fail in impossible-to-find way, at
least not directly.
In GHC, you can wrap or replace them with irrefutable patterns which are
almost as easy to write, and will give you a sensible error message if
they fail.
Example:
replace x = head xx
with (x:_) = xx
replace x = fromJust mX
with (Just x) = mX
replace x = last xx
with
y@(_:_) = xx
x = last y
Ben.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe