Skip to content

Commit

Permalink
createTrivialTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 28, 2023
1 parent c98b61d commit 1d05344
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 83 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
`createTrivialTypes`

`Type` should be type instead of class

[maybe] quit using `def/` and `defs/`
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/design-of-new-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ end
We use a simple type system like Haskell (for now).

```inet
defnode sole -- !Sole end
defnode sole -- !Trivial end
defnode null -- !List('a) end
Expand Down
11 changes: 3 additions & 8 deletions src/lang/mod/builtInOperators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Mod } from "."
import * as Defs from "../defs"
import { Port } from "../graph"
import { netConnect } from "../graph/netConnect"
import { buildTypes } from "../types"
import { createTrivialTypes } from "../type"

export function builtInOperators(mod: Mod): void {
mod.defineOperator("swap", (net) => {
Expand All @@ -25,13 +25,8 @@ export function builtInOperators(mod: Mod): void {
})

mod.defineOperator("wire", (net) => {
const def = new Defs.NodeDef(
mod,
"Cons",
"wire",
[],
buildTypes(["Any", "Any"]),
)
const def = new Defs.NodeDef(mod, "Cons", "wire", [], createTrivialTypes(2))

const node = def.build()

net.portStack.push(...node.output)
Expand Down
6 changes: 3 additions & 3 deletions src/lang/stmts/DefconsStmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Defs from "../defs"
import { Mod } from "../mod"
import { Span } from "../span"
import { Stmt } from "../stmt"
import { buildTypes } from "../types"
import { createTrivialTypes } from "../type"

export class DefconsStmt extends Stmt {
constructor(
Expand All @@ -21,8 +21,8 @@ export class DefconsStmt extends Stmt {
mod,
"Cons",
this.name,
buildTypes(Array(this.inputArity).fill("Any")),
buildTypes(Array(this.outputArity).fill("Any")),
createTrivialTypes(this.inputArity),
createTrivialTypes(this.outputArity),
),
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/lang/stmts/DefelimStmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Defs from "../defs"
import { Mod } from "../mod"
import { Span } from "../span"
import { Stmt } from "../stmt"
import { buildTypes } from "../types"
import { createTrivialTypes } from "../type"

export class DefelimStmt extends Stmt {
constructor(
Expand All @@ -21,8 +21,8 @@ export class DefelimStmt extends Stmt {
mod,
"Elim",
this.name,
buildTypes(Array(this.inputArity).fill("Any")),
buildTypes(Array(this.outputArity).fill("Any")),
createTrivialTypes(this.inputArity),
createTrivialTypes(this.outputArity),
),
)
}
Expand Down
8 changes: 1 addition & 7 deletions src/lang/type/Type.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
export abstract class Type {
abstract format(): string

isPrincipal(): boolean {
return false
}
}
export type Type = {}
5 changes: 5 additions & 0 deletions src/lang/type/createTrivialTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Type } from "./Type"

export function createTrivialTypes(arity: number): Array<Type> {
return Array(arity).fill({})
}
1 change: 1 addition & 0 deletions src/lang/type/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./Type"
export * from "./createTrivialTypes"
14 changes: 0 additions & 14 deletions src/lang/types/AtomType.ts

This file was deleted.

34 changes: 0 additions & 34 deletions src/lang/types/TypeBuilder.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/lang/types/buildTypes.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/lang/types/index.ts

This file was deleted.

0 comments on commit 1d05344

Please sign in to comment.