2021-05-27 20:39:09 +03:00
|
|
|
|
```unison
|
2021-08-24 21:33:27 +03:00
|
|
|
|
structural ability Exception where raise : Failure -> x
|
2021-05-27 20:39:09 +03:00
|
|
|
|
|
|
|
|
|
ex = unsafeRun! '(printLine "hello world")
|
|
|
|
|
|
|
|
|
|
printLine : Text ->{IO, Exception} ()
|
|
|
|
|
printLine t =
|
|
|
|
|
putText stdOut t
|
|
|
|
|
putText stdOut "\n"
|
|
|
|
|
|
|
|
|
|
stdOut : Handle
|
|
|
|
|
stdOut = stdHandle StdOut
|
|
|
|
|
|
2021-06-08 21:50:04 +03:00
|
|
|
|
compose2 : (c ->{𝕖1} d) -> (a ->{𝕖2} b ->{𝕖3} c) -> a -> b ->{𝕖1,𝕖2,𝕖3} d
|
2021-05-27 20:39:09 +03:00
|
|
|
|
compose2 f g x y = f (g x y)
|
|
|
|
|
|
|
|
|
|
putBytes : Handle -> Bytes ->{IO, Exception} ()
|
|
|
|
|
putBytes = compose2 toException putBytes.impl
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
Exception.unsafeRun! : '{Exception, g} a -> '{g} a
|
|
|
|
|
Exception.unsafeRun! e _ =
|
|
|
|
|
h : Request {Exception} a -> a
|
|
|
|
|
h = cases
|
|
|
|
|
{Exception.raise fail -> _ } ->
|
|
|
|
|
bug fail
|
|
|
|
|
{a} -> a
|
|
|
|
|
handle !e with h
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
|
2021-05-27 20:39:09 +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 ability Exception
|
2021-07-26 22:35:42 +03:00
|
|
|
|
(also named builtin.Exception)
|
2021-05-27 20:39:09 +03:00
|
|
|
|
Exception.unsafeRun! : '{g, Exception} a -> '{g} a
|
2021-06-08 21:50:04 +03:00
|
|
|
|
compose2 : (c ->{𝕖1} d)
|
|
|
|
|
-> (a ->{𝕖2} b ->{𝕖3} c)
|
2021-05-27 20:39:09 +03:00
|
|
|
|
-> a
|
|
|
|
|
-> b
|
2021-06-08 21:50:04 +03:00
|
|
|
|
->{𝕖1, 𝕖2, 𝕖3} d
|
2021-05-27 20:39:09 +03:00
|
|
|
|
ex : '{IO} ()
|
|
|
|
|
printLine : Text ->{IO, Exception} ()
|
|
|
|
|
putBytes : Handle
|
|
|
|
|
-> Bytes
|
|
|
|
|
->{IO, Exception} ()
|
|
|
|
|
putText : Handle -> Text ->{IO, Exception} ()
|
|
|
|
|
stdOut : Handle
|
|
|
|
|
toException : Either Failure a ->{Exception} a
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
```ucm
|
|
|
|
|
.> run ex
|
|
|
|
|
|
2022-08-15 21:30:14 +03:00
|
|
|
|
()
|
|
|
|
|
|
2021-05-27 20:39:09 +03:00
|
|
|
|
```
|