Curious behaviour of irrefutable pattern.

Simon Peyton-Jones simonpj at microsoft.com
Wed Dec 20 04:28:52 EST 2006


Strictness analysis generally treats non-termination and errors (calls to 'error') the same.  It decides that f is strict (that is f bot = bot), and hence it can use call-by-value.

In general, GHC (like every other compiler that does strictness analysis) feels free to change non-termination into a call to 'error' and vice versa.  One could change that, but a lot of programs would become less efficient as a result.

Simon

| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-
| haskell-users-bounces at haskell.org] On Behalf Of Bertram Felgenhauer
| Sent: 20 December 2006 09:04
| To: glasgow-haskell-users at haskell.org
| Subject: Curious behaviour of irrefutable pattern.
|
| Hi,
|
| 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
| versa.
|
| Anyway, this looks suspicious to me, so what's happening here?
|
| regards,
|
| Bertram
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


More information about the Glasgow-haskell-users mailing list