Curious behaviour of irrefutable pattern.

Bertram Felgenhauer bertram.felgenhauer at
Wed Dec 20 04:04:13 EST 2006


consider this program:

> module Main (f, main) where
> f ~(a:as) = 1 + f as
> main = print $ f (error "Foobar!")

Obviously, the program should result in an error - the irrefutable
pattern of f always succeeds, so f calls itself recursively ad
infinitum and the result is <<Loop>> or nontermination.

Or so I thought. Running this program after compiling with ghc -O
(with 6.4.2, 6.6 and 6.7) results in:

  a.out: Foobar!

So the 'error "Foobar!"' got evaluated. The compiler somehow replaced
one 'bottom' with another which is arguably allowed. I wasn't able to
come up with an example where it turned a bottom into a value or vice

Anyway, this looks suspicious to me, so what's happening here?



More information about the Glasgow-haskell-users mailing list