humbug = do
match (5, 6) with z ->
trace "before" z
match 99 with n -> ()
trace "after" z
produces unexpected output:
> run humbug
trace: before
(5, 6)
trace: after
99
I believe the reason is that the pattern match compiler is capturing variables. To handle the 'whole result' match, it introduces a new name for compound expressions in the scrutinee, and I think it isn't being freshened enough. So, the z get substituted with the variable for the (5,6) match, then captured for the 99 match, because the scope is not limited to the match.
Code like the following:
produces unexpected output:
I believe the reason is that the pattern match compiler is capturing variables. To handle the 'whole result' match, it introduces a new name for compound expressions in the scrutinee, and I think it isn't being freshened enough. So, the
z
get substituted with the variable for the(5,6)
match, then captured for the99
match, because the scope is not limited to the match.