BangPatterns + ViewPatterns
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
.
Trac metadata
Trac field | Value |
---|---|
Version | 7.7 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |