aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-15 00:29:18 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-15 00:29:18 +0530
commit853112fcb4cfd44d39f0232d2e9b465636e3cc7d (patch)
tree1def8f2f6599af4e9a6a56867b90cdc9df4bc754
parentd5c3af89ab8076bcf4107859c1ba6b47a7815142 (diff)
downloadts-types-lang-853112fcb4cfd44d39f0232d2e9b465636e3cc7d.tar.gz
ts-types-lang-853112fcb4cfd44d39f0232d2e9b465636e3cc7d.zip
chore: better example
-rw-r--r--README.md47
-rw-r--r--examples/greeting.ts25
2 files changed, 54 insertions, 18 deletions
diff --git a/README.md b/README.md
index 25c9c85..4f6900c 100644
--- a/README.md
+++ b/README.md
@@ -1,28 +1,57 @@
# TS Types lang
A runtime for typescript's **type system** that turns it into a **general purpose**, **purely functional** programming language with effects!
-### Documentation
+## Documentation
- [stdlib reference](./docs/modules.md)
- [examples](./examples/)
-### Example
+## Implemented effects
+ * read/write file
+ * simple stdio interactions
+ * error handling
+ * test runner
+ * mutable references
+ * evaluate js expression
+ * get cli args, env vars
+ * define custom effects
-Take a look at the [./examples](./examples) directory for more examples on how to write a program in typescript types
+
+## Example
+
+Take a look at the [./examples](./examples/) directory for more examples on how to write a program in typescript types
```typescript
-import { Bind } from 'ts-types-lang/stdlib/effect'
-import { PutString, PutStringLn, ReadLine } from 'ts-types-lang/stdlib/stdio'
+import { Bind, Do, Kind1 } from 'ts-types-lang/stdlib/effect'
+import { WriteFile } from 'ts-types-lang/stdlib/fs'
+import { PutString, ReadLine, PutStringLn } from 'ts-types-lang/stdlib/stdio'
export type main = [
- PutString<"Your name? ">,
- // Read a line from stdin and then greet
+ PutStringLn<'Greetotron 6000 initializing...'>,
+ PutStringLn<''>,
+
+ PutString<'Your name? '>,
Bind<ReadLine, <name extends string>() =>
PutStringLn<`Hello, ${name}`>>,
+
+ PutString<'Your purpose in life? '>,
+ Bind<ReadLine, HandleResponseK>,
+
+ PutStringLn<'Bye bye'>,
]
+
+// :: string -> Effect ()
+interface HandleResponseK extends Kind1<string, Effect> {
+ return: Do<[
+ PutStringLn<`Interesting that you believe "${this['input']}" is your purpose. Hmmmm...`>,
+ PutStringLn<'Judging harshly...'>,
+ PutStringLn<'Saving response...'>,
+ WriteFile<'./response.txt', this['input']>,
+ ]>
+}
```
-### Run a types-lang module
+## Run a types-lang module
Install it -
```bash
@@ -39,7 +68,7 @@ yarn exec tsr run ./examples/guess-number.ts
```
-### FAQ
+## FAQ
#### Why?
I dunno
diff --git a/examples/greeting.ts b/examples/greeting.ts
index 72edde2..f285313 100644
--- a/examples/greeting.ts
+++ b/examples/greeting.ts
@@ -1,20 +1,27 @@
-import { Bind, Kind1 } from '../stdlib/effect'
+import { Bind, Do, Kind1 } from '../stdlib/effect'
+import { WriteFile } from '../stdlib/fs'
import { PutString, ReadLine, PutStringLn } from '../stdlib/stdio'
-interface ResponseK extends Kind1<string> {
- return: PutStringLn<`Interesting that you believe "${this['input']}" is your purpose. Hmmmm...`>
-}
-
export type main = [
PutStringLn<'Greetotron 6000 initializing...'>,
+ PutStringLn<''>,
- PutStringLn<'----------------'>,
PutString<'Your name? '>,
Bind<ReadLine, <name extends string>() => PutStringLn<`Hello, ${name}`>>,
- PutStringLn<'----------------'>,
PutString<'Your purpose in life? '>,
- Bind<ReadLine, ResponseK>,
+ Bind<ReadLine, HandleResponseK>,
- PutStringLn<'----------------'>
+ PutStringLn<'Bye bye'>
]
+
+interface HandleResponseK extends Kind1<string> {
+ return: Do<
+ [
+ PutStringLn<`Interesting that you believe "${this['input']}" is your purpose. Hmmmm...`>,
+ PutStringLn<'Judging harshly...'>,
+ PutStringLn<'Saving response...'>,
+ WriteFile<'./response.txt', this['input']>
+ ]
+ >
+}