Opened 2 years ago

Closed 2 years ago

#7649 closed bug (fixed)

BangPatterns + ViewPatterns

Reported by: igloo Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: stranal/should_run/T7649
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

This program:

{-# LANGUAGE ViewPatterns, BangPatterns #-}

import Control.Exception

main :: IO ()
main = do print (f False)
          print (f True)
          print (g undefined) `catchE` \_ -> putStrLn "g exception"
          print (h undefined) `catchE` \_ -> putStrLn "h exception"
          print (i undefined) `catchE` \_ -> putStrLn "i exception"
          putStrLn "Done"

f :: Bool -> String
f (view -> Nothing) = "Got Nothing"
f (view -> Just x)  = "Got Just " ++ show x

g :: Bool -> String
g (view -> x) = "g Got something"

h :: Bool -> String
h (view -> !x) = "h Got something"

i :: Bool -> String
i !(view -> x) = "i Got something"

view :: Bool -> Maybe Int
view False = Nothing
view True = Just 5

catchE :: IO a -> (ErrorCall -> IO a) -> IO a
catchE = catch

prints:

"Got Nothing"
"Got Just 5"
"g Got something"
"h exception
"i Got something"
Done

but presumably i ought to be strict in x.

Change History (2)

comment:1 Changed 2 years ago by simonpj@…

commit 44302272b568bc86f0e62579f6707e6e9ae8e4ab

Author: Simon Peyton Jones <[email protected]>
Date:   Wed Feb 13 17:42:18 2013 +0000

    Desugar bang patterns correctly (fixes Trac #7649)
    
    We were discarding a bang around a view pattern, which is
    utterly wrong

 compiler/deSugar/Match.lhs |   42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 deletions(-)

comment:2 Changed 2 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to stranal/should_run/T7649

Indeed, it was utterly wrong before. Thank you.

Simon

Note: See TracTickets for help on using tickets.