The Semantics of Asynchronous Exceptions

8
Semantics of Asynchronous Exceptions

Transcript of The Semantics of Asynchronous Exceptions

Page 1: The Semantics of Asynchronous Exceptions

8/14/2019 The Semantics of Asynchronous Exceptions

http://slidepdf.com/reader/full/the-semantics-of-asynchronous-exceptions 1/8

Semantics of AsynchronousExceptions

Page 2: The Semantics of Asynchronous Exceptions

8/14/2019 The Semantics of Asynchronous Exceptions

http://slidepdf.com/reader/full/the-semantics-of-asynchronous-exceptions 2/8

© 2010 Galois, Inc. All r ights reserved.

Conventions and Notations

Primitive IO actions are considered “values” for the purely functional part of thesemantics (>>=, putChar, block etc)

Evaluation contexts are assumed to be maximal

• F  = [.] | F >>= M | catch F H

• E  = F  | F [ block E ] | F [ unblock E ]

Threads can be:

• Stuck: ( … )•

• Runnable: ( … )o

Page 3: The Semantics of Asynchronous Exceptions

8/14/2019 The Semantics of Asynchronous Exceptions

http://slidepdf.com/reader/full/the-semantics-of-asynchronous-exceptions 3/8

© 2010 Galois, Inc. All r ights reserved.

IO Primitives

Page 4: The Semantics of Asynchronous Exceptions

8/14/2019 The Semantics of Asynchronous Exceptions

http://slidepdf.com/reader/full/the-semantics-of-asynchronous-exceptions 4/8

© 2010 Galois, Inc. All r ights reserved.

Threads and Exceptions

Page 5: The Semantics of Asynchronous Exceptions

8/14/2019 The Semantics of Asynchronous Exceptions

http://slidepdf.com/reader/full/the-semantics-of-asynchronous-exceptions 5/8

© 2010 Galois, Inc. All r ights reserved.

Basic Transitions

Page 6: The Semantics of Asynchronous Exceptions

8/14/2019 The Semantics of Asynchronous Exceptions

http://slidepdf.com/reader/full/the-semantics-of-asynchronous-exceptions 6/8

© 2010 Galois, Inc. All r ights reserved.

Asynchronous Exceptions

Page 7: The Semantics of Asynchronous Exceptions

8/14/2019 The Semantics of Asynchronous Exceptions

http://slidepdf.com/reader/full/the-semantics-of-asynchronous-exceptions 7/8

Page 8: The Semantics of Asynchronous Exceptions

8/14/2019 The Semantics of Asynchronous Exceptions

http://slidepdf.com/reader/full/the-semantics-of-asynchronous-exceptions 8/8

© 2010 Galois, Inc. All r ights reserved.

Higher-level Operators

onException :: IO a -> IO b -> IO aonException io what

= io `catch` (\e -> what >> throw (e :: SomeException))

finally :: IO a -> IO b -> IO aa `finally` sequel = block $ do

r <- unblock a `onException` sequelsequelreturn r 

try :: Exception e => IO a -> IO (Either e a)try a = (a >>= (return . Right)) `catch` (return . Left)