Bug in Hugs, Haskell behavior question

In lab the other day I was showing pattern bindings to a student and broached a limiting case, one with no variables to be bound in the pattern. I was surprised to find that Hugs crashed when I tried a pattern binding at top level like this: (2,[1,4],5) = (2,[1,4],5) It also crashed on the simpler: [2] = [2] On the other hand, this turns out to be acceptable: 2 = 2 In fact, even this goes through without a hitch! 2 = 3 I'm not sure from the language definition yet whether this last should give an "Unmatched pattern" error, but if it's intended behavior, it does look a little odd. Would anyone care to argue for or against allowing this? In any case, the more structured patterns cause the latest (Sep 06) Hugs release to crash, with "INTERNAL ERROR: compileGlobalFunction". (GHC allows the strange "2 = 3" and handles the structured ones fine, including even "(1,[2,3],4) = (4,[3,37],42)". I haven't checked any other compilers.) -- Fritz

On Fri, 2008-04-04 at 18:34 -0700, Fritz Ruehr wrote:
In lab the other day I was showing pattern bindings to a student and broached a limiting case, one with no variables to be bound in the pattern. I was surprised to find that Hugs crashed when I tried a pattern binding at top level like this:
(2,[1,4],5) = (2,[1,4],5)
It also crashed on the simpler:
[2] = [2]
On the other hand, this turns out to be acceptable:
2 = 2
In fact, even this goes through without a hitch!
2 = 3
I'm not sure from the language definition yet whether this last should give an "Unmatched pattern" error, but if it's intended behavior, it does look a little odd.
Would anyone care to argue for or against allowing this?
In any case, the more structured patterns cause the latest (Sep 06) Hugs release to crash, with "INTERNAL ERROR: compileGlobalFunction".
(GHC allows the strange "2 = 3" and handles the structured ones fine, including even "(1,[2,3],4) = (4,[3,37],42)". I haven't checked any other compilers.)
Top-level bindings are irrefutable, so 2 = 3 is fine, if vacuous.

On 4/4/08, Fritz Ruehr
In fact, even this goes through without a hitch!
2 = 3
This is hilarious. Maybe bindings that don't actually bind anything should be an error? Or at least a warning? In ghci: Prelude> let 2 = 3 -- no problem Prelude> let (2,x) = (3,4) -- no problem Prelude> x *** Exception: <interactive>:1:4-16: Irrefutable pattern match failed for pattern (2,x) -- ryan

Derek: yes, I caught this in the language description not long after hitting "send": I had forgotten about that. But then I anticipated the behavior Ryan shows below, where using a variable that's part of a "strange" pattern will cause an error (I didn't want to check it while driving home--cell phone user/drivers are bad enough!--so thanks, Ryan, for verifying :) ). In any case, opinions about the behavior aside, there is a Hugs internal error here, so I hope that much is useful. The strange cases make for interesting academic discussions, at least. -- Fritz On Fri 4 Apr 08, at 6:49 pm, Derek Elkins wrote:
Top-level bindings are irrefutable, so 2 = 3 is fine, if vacuous.
On Fri 4 Apr 08, at 6:53 pm, Ryan Ingram wrote:
On 4/4/08, Fritz Ruehr
wrote: In fact, even this goes through without a hitch!
2 = 3
This is hilarious.
Maybe bindings that don't actually bind anything should be an error? Or at least a warning?
In ghci:
Prelude> let 2 = 3 -- no problem Prelude> let (2,x) = (3,4) -- no problem Prelude> x *** Exception: <interactive>:1:4-16: Irrefutable pattern match failed for pattern (2,x)
-- ryan

On Apr 4, 2008, at 23:15 , Fritz Ruehr wrote:
In any case, opinions about the behavior aside, there is a Hugs internal error here, so I hope that much is useful.
I am not greatly surprised by that: a numeric constant like `2' is really a polymorphic value `(fromInteger 2 :: Num a => a)' per the Report, and if Hugs does that conversion at the wrong time then it might well end up attempting to turn a function call into a pattern (normally impossible in Haskell, as any attempt would either shadow the function or raise a syntax error). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
participants (4)
-
Brandon S. Allbery KF8NH
-
Derek Elkins
-
Fritz Ruehr
-
Ryan Ingram