``` unison structural ability Exception where raise : Failure -> x reraise = cases Left e -> raise e Right a -> a structural type Either a b = Left a | Right b putBytes h bs = reraise (putBytes.impl h bs) toException : Either Failure a ->{Exception} a toException = cases Left e -> raise e Right a -> a putText : Handle -> Text ->{IO, Exception} () putText h t = putBytes h (toUtf8 t) bugFail = cases Failure typ _ _ -> bug (Failure typ "problem" (Any ())) Exception.unsafeRun! : '{Exception, g} a -> '{g} a Exception.unsafeRun! e _ = h : Request {Exception} a -> a h = cases {Exception.raise fail -> _ } -> bugFail fail {a} -> a handle !e with h socketSend s bytes = reraise (socketSend.impl s bytes) closeSocket s = reraise (closeSocket.impl s) serverSocket host port = reraise (IO.serverSocket.impl host port) hello : Text -> Text -> {IO, Exception} () hello host port = socket = serverSocket (Some host) port msg = toUtf8 "Hello there" socketSend socket msg closeSocket socket myServer = unsafeRun! '(hello "127.0.0.1" "0") ``` ``` ucm Loading changes detected in scratch.u. I found and typechecked these definitions in scratch.u. If you do an `add` or `update`, here's how your codebase would change: ⍟ These new definitions are ok to `add`: structural type Either a b (also named builtin.Either) structural ability Exception (also named builtin.Exception) Exception.unsafeRun! : '{g, Exception} a -> '{g} a bugFail : Failure -> r closeSocket : Socket ->{IO, Exception} () hello : Text -> Text ->{IO, Exception} () myServer : '{IO} () putBytes : Handle -> Bytes ->{IO, Exception} () putText : Handle -> Text ->{IO, Exception} () reraise : Either Failure b ->{Exception} b serverSocket : Optional Text -> Text ->{IO, Exception} Socket socketSend : Socket -> Bytes ->{IO, Exception} () toException : Either Failure a ->{Exception} a ``` ``` ucm scratch/main> run myServer 💔💥 I've encountered a call to builtin.bug with the following value: Failure (typeLink IOFailure) "problem" (Any ()) Stack trace: bug #8ppr1tt4q2 ```