2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2021-08-24 21:33:27 +03:00
|
|
|
structural ability Exception where raise : Failure -> x
|
2021-06-08 07:01:06 +03:00
|
|
|
|
|
|
|
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
|
2021-06-08 07:01:06 +03:00
|
|
|
|
|
|
|
putBytes h bs = reraise (putBytes.impl h bs)
|
|
|
|
|
2021-05-27 23:41:14 +03:00
|
|
|
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)
|
|
|
|
|
2021-05-28 01:37:55 +03:00
|
|
|
bugFail = cases
|
|
|
|
Failure typ _ _ -> bug (Failure typ "problem" (Any ()))
|
|
|
|
|
2021-05-27 23:41:14 +03:00
|
|
|
Exception.unsafeRun! : '{Exception, g} a -> '{g} a
|
2021-06-08 07:01:06 +03:00
|
|
|
Exception.unsafeRun! e _ =
|
|
|
|
h : Request {Exception} a -> a
|
|
|
|
h = cases
|
|
|
|
{Exception.raise fail -> _ } ->
|
2021-05-28 01:37:55 +03:00
|
|
|
bugFail fail
|
2021-06-08 07:01:06 +03:00
|
|
|
{a} -> a
|
|
|
|
handle !e with h
|
|
|
|
|
|
|
|
socketSend s bytes = reraise (socketSend.impl s bytes)
|
|
|
|
closeSocket s = reraise (closeSocket.impl s)
|
2024-04-02 09:12:34 +03:00
|
|
|
serverSocket host port = reraise (IO.serverSocket.impl host port)
|
2021-05-27 23:41:14 +03:00
|
|
|
|
|
|
|
hello : Text -> Text -> {IO, Exception} ()
|
2021-06-08 07:01:06 +03:00
|
|
|
hello host port =
|
2021-05-27 23:41:14 +03:00
|
|
|
socket = serverSocket (Some host) port
|
2021-06-08 07:01:06 +03:00
|
|
|
msg = toUtf8 "Hello there"
|
2021-05-27 23:41:14 +03:00
|
|
|
socketSend socket msg
|
2021-06-08 07:01:06 +03:00
|
|
|
closeSocket socket
|
2021-05-27 23:41:14 +03:00
|
|
|
|
|
|
|
myServer = unsafeRun! '(hello "127.0.0.1" "0")
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2021-05-27 23:41:14 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2021-05-27 23:41:14 +03:00
|
|
|
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`:
|
|
|
|
|
2021-08-24 21:33:27 +03:00
|
|
|
structural type Either a b
|
2021-06-08 07:01:06 +03:00
|
|
|
(also named builtin.Either)
|
2024-04-15 03:01:39 +03:00
|
|
|
structural ability Exception
|
|
|
|
(also named builtin.Exception)
|
2022-01-25 09:27:16 +03:00
|
|
|
Exception.unsafeRun! : '{g, Exception} a -> '{g} a
|
2024-04-15 03:01:39 +03:00
|
|
|
bugFail : Failure -> r
|
2022-01-25 09:27:16 +03:00
|
|
|
closeSocket : Socket ->{IO, Exception} ()
|
2024-04-15 03:01:39 +03:00
|
|
|
hello : Text -> Text ->{IO, Exception} ()
|
|
|
|
myServer : '{IO} ()
|
2022-01-25 09:27:16 +03:00
|
|
|
putBytes : Handle
|
|
|
|
-> Bytes
|
|
|
|
->{IO, Exception} ()
|
2024-04-15 03:01:39 +03:00
|
|
|
putText : Handle -> Text ->{IO, Exception} ()
|
|
|
|
reraise : Either Failure b ->{Exception} b
|
2022-01-25 09:27:16 +03:00
|
|
|
serverSocket : Optional Text
|
|
|
|
-> Text
|
|
|
|
->{IO, Exception} Socket
|
2024-04-15 03:01:39 +03:00
|
|
|
socketSend : Socket
|
|
|
|
-> Bytes
|
|
|
|
->{IO, Exception} ()
|
|
|
|
toException : Either Failure a ->{Exception} a
|
2021-05-27 23:41:14 +03:00
|
|
|
|
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run myServer
|
2021-05-27 23:41:14 +03:00
|
|
|
|
|
|
|
💔💥
|
|
|
|
|
|
|
|
I've encountered a call to builtin.bug with the following
|
|
|
|
value:
|
|
|
|
|
2022-02-13 08:20:06 +03:00
|
|
|
Failure (typeLink IOFailure) "problem" (Any ())
|
2021-05-27 23:41:14 +03:00
|
|
|
|
2022-10-20 23:21:15 +03:00
|
|
|
Stack trace:
|
|
|
|
bug
|
2023-08-18 00:55:28 +03:00
|
|
|
#8ppr1tt4q2
|
2021-05-27 23:41:14 +03:00
|
|
|
|
|
|
|
```
|