Bug in Hugs, Haskell behavior question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in Hugs, Haskell behavior question

Fritz Ruehr
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
_______________________________________________
Hugs-Bugs mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/hugs-bugs
Reply | Threaded
Open this post in threaded view
|

Re: [Haskell-cafe] Bug in Hugs, Haskell behavior question

Fritz Ruehr
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 <[hidden email]> 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


_______________________________________________
Hugs-Bugs mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/hugs-bugs