2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2021-04-28 05:29:38 +03:00
|
|
|
printLine : Text ->{IO} ()
|
|
|
|
printLine msg =
|
2022-12-02 08:51:11 +03:00
|
|
|
_ = putBytes.impl (stdHandle StdOut) (Text.toUtf8 (msg ++ "\n"))
|
2021-04-28 05:29:38 +03:00
|
|
|
()
|
|
|
|
|
|
|
|
-- An unannotated main function
|
|
|
|
main1 = '(printLine "\nhello world!")
|
|
|
|
|
|
|
|
-- Another variation
|
|
|
|
main2 _ = printLine "🌹"
|
|
|
|
|
|
|
|
-- An annotated main function
|
|
|
|
main3 : '{IO} ()
|
|
|
|
main3 _ = printLine "🦄 ☁️ 🌈"
|
|
|
|
```
|
|
|
|
|
|
|
|
Testing a few variations here:
|
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
- Should be able to run annotated and unannotated main functions in the current file.
|
|
|
|
- Should be able to run annotated and unannotated main functions from the codebase.
|
2021-04-28 05:29:38 +03:00
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run main1
|
2021-04-28 05:29:38 +03:00
|
|
|
|
2022-08-15 21:30:14 +03:00
|
|
|
()
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run main2
|
2021-04-28 05:29:38 +03:00
|
|
|
|
2022-08-15 21:30:14 +03:00
|
|
|
()
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run main3
|
2021-04-28 05:29:38 +03:00
|
|
|
|
2022-08-15 21:30:14 +03:00
|
|
|
()
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
2021-04-28 05:29:38 +03:00
|
|
|
|
|
|
|
⍟ I've added these definitions:
|
|
|
|
|
|
|
|
main1 : '{IO} ()
|
|
|
|
main2 : ∀ _. _ ->{IO} ()
|
|
|
|
main3 : '{IO} ()
|
|
|
|
printLine : Text ->{IO} ()
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> rename.term main1 code.main1
|
2021-04-28 05:29:38 +03:00
|
|
|
|
|
|
|
Done.
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> rename.term main2 code.main2
|
2021-04-28 05:29:38 +03:00
|
|
|
|
|
|
|
Done.
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> rename.term main3 code.main3
|
2021-04-28 05:29:38 +03:00
|
|
|
|
|
|
|
Done.
|
|
|
|
|
|
|
|
```
|
|
|
|
The renaming just ensures that when running `code.main1`, it has to get that main from the codebase rather than the scratch file:
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run code.main1
|
2021-04-28 05:29:38 +03:00
|
|
|
|
2022-08-15 21:30:14 +03:00
|
|
|
()
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run code.main2
|
2021-04-28 05:29:38 +03:00
|
|
|
|
2022-08-15 21:30:14 +03:00
|
|
|
()
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run code.main3
|
2021-04-28 05:29:38 +03:00
|
|
|
|
2022-08-15 21:30:14 +03:00
|
|
|
()
|
|
|
|
|
2021-04-28 05:29:38 +03:00
|
|
|
```
|
|
|
|
Now testing a few variations that should NOT typecheck.
|
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2021-04-28 05:29:38 +03:00
|
|
|
main4 : Nat ->{IO} Nat
|
|
|
|
main4 n = n
|
|
|
|
|
|
|
|
main5 : Nat ->{IO} ()
|
|
|
|
main5 _ = ()
|
|
|
|
```
|
|
|
|
|
|
|
|
This shouldn't work since `main4` and `main5` don't have the right type.
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run main4
|
2021-04-28 05:29:38 +03:00
|
|
|
|
|
|
|
😶
|
|
|
|
|
|
|
|
I found this function:
|
|
|
|
|
|
|
|
main4 : Nat ->{IO} Nat
|
|
|
|
|
2023-12-13 23:22:11 +03:00
|
|
|
but in order for me to `run` it needs to be a subtype of:
|
2021-04-28 05:29:38 +03:00
|
|
|
|
2022-08-22 18:48:13 +03:00
|
|
|
main4 : '{IO, Exception} result
|
2021-04-28 05:29:38 +03:00
|
|
|
|
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run main5
|
2021-04-28 05:29:38 +03:00
|
|
|
|
|
|
|
😶
|
|
|
|
|
|
|
|
I found this function:
|
|
|
|
|
|
|
|
main5 : Nat ->{IO} ()
|
|
|
|
|
2023-12-13 23:22:11 +03:00
|
|
|
but in order for me to `run` it needs to be a subtype of:
|
2021-04-28 05:29:38 +03:00
|
|
|
|
2022-08-22 18:48:13 +03:00
|
|
|
main5 : '{IO, Exception} result
|
2021-04-28 05:29:38 +03:00
|
|
|
|
|
|
|
```
|