Skip to content

Commit

Permalink
2023-11-17-type-system.md
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Nov 17, 2023
1 parent fb9ef31 commit 127e160
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DefineType & TypeDefinition
DefineDatatype & DatatypeDefinition

- `type <name>` -- to define trivial type for now
- `datatype <name>` -- to define trivial type for now
- pass parser `tests/`

# net
Expand Down
28 changes: 28 additions & 0 deletions docs/diary/2023-11-17-type-system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Type system
author: Xie Yuheng
date: 2023-11-17
---

We want algebraic datatype,
but we also want the data to be easily usable in JavaScript.

We can use named record data:

```petri-net
datatype Exp {
Var { name: String }
Fn { name: String, body: Exp }
Ap { target: Exp, arg: Exp }
}
```

Corresponding to the following TypeScript types:

```typescript
type Exp = Var | Fn | Ap

type Var = { "@type": "Exp", "@kind": "Var", name: String }
type Fn = { "@type": "Exp", "@kind": "Fn", name: String, body: Exp }
type Ap = { "@type": "Exp", "@kind": "Ap", target: Exp, arg: Exp }
```

0 comments on commit 127e160

Please sign in to comment.