unison/unison-src/transcripts/fix2027.md

56 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

```ucm:hide
scratch/main> builtins.merge
```
```unison
2021-08-24 21:33:27 +03:00
structural ability Exception where raise : Failure -> x
reraise = cases
Left e -> raise e
Right a -> a
2021-08-24 21:33:27 +03:00
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)
2024-04-02 09:11:34 +03:00
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:error
scratch/main> run myServer
```