0.1.36 • Published 8 months ago

@cicada-lang/inet v0.1.36

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
8 months ago

iNet.js

[ Website ]

This is an implementation of interaction nets. It introduces you to the bizarre world of graph-based computation and linear logic, using a familiar JavaScript-like syntax :)

Usage

Command line tool

Install it by the following command:

npm install --global @cicada-lang/inet

The command line program is called inet.js.

inet.js repl         # Open an interactive REPL
inet.js run [path]   # Run an inet program
inet.js help [name]  # Display help for a command

Examples

Nat

TODO Playground

type Nat

node zero(
  ------
  value!: Nat
)

node add1(
  prev: Nat
  ----------
  value!: Nat
)

node add(
  target!: Nat,
  addend: Nat
  --------
  result: Nat
)

rule add(target!, addend, result) zero(value!) {
  @connect(addend, result)
}

rule add(target!, addend, result) add1(prev, value!) {
  add1(add(prev, addend), result)
}

function one(): Nat {
  return add1(zero())
}

function two(): Nat {
  return add(one(), one())
}

function three(): Nat {
  return add(two(), one())
}

function four(): Nat {
  return add(two(), two())
}

// TEST

eval @inspect(add(two(), two()))
eval @inspect(@run(add(two(), two())))

List

TODO Playground

type List(Element: @Type)

node null(
  --------
  value!: List('A)
)

node cons(
  head: 'A,
  tail: List('A)
  --------
  value!: List('A)
)

node append(
  target!: List('A),
  rest: List('A)
  --------
  result: List('A)
)

rule append(target!, rest, result) null(value!) {
  @connect(rest, result)
}

rule append(target!, rest, result) cons(head, tail, value!) {
  cons(head, append(tail, rest), result)
}

// TEST

type Trivial

node sole(-- value!: Trivial)

function sixSoles(): List(Trivial) {
  return append(
    cons(sole(), cons(sole(), cons(sole(), null()))),
    cons(sole(), cons(sole(), cons(sole(), null()))),
  )
}

eval @inspect(sixSoles())
eval @inspect(@run(sixSoles()))

DiffList

TODO Playground

import { List } from "https://code-of-inet-js.fidb.app/std/datatype/List.i"

// Concatenation of lists is performed in linear time
// with respect to its first argument.
// Constant time concatenation is possible
// with difference-lists: the idea consists in
// plugging the front of the second argument
// at the back of the first one.

type DiffList(Element: @Type)

node diff(
  front: List('A),
  -------
  back: List('A),
  value!: DiffList('A),
)

node diffAppend(
  target!: DiffList('A),
  rest: DiffList('A)
  --------
  result: DiffList('A)
)

node diffOpen(
  target!: DiffList('A),
  newBack: List('A)
  ----------
  oldBack: List('A)
)

rule diffAppend(target!, rest, result)
     diff(front, back, value!) {
  let newBack, value = diff(front)
  @connect(value, result)
  diffOpen(rest, newBack, back)
}

rule diffOpen(target!, newBack, oldBack)
     diff(front, back, value!) {
  @connect(back, newBack)
  @connect(front, oldBack)
}

// TEST

import { cons } from "https://code-of-inet-js.fidb.app/std/datatype/List.i"

type Trivial

node sole(-- value!: Trivial)

function twoTwoSoles(): DiffList(Trivial) {
  let front, back, value1 = diff()
  @connect(front, cons(sole(), cons(sole(), back)))
  let front, back, value2 = diff()
  @connect(front, cons(sole(), cons(sole(), back)))
  return diffAppend(value1, value2)
}

eval @inspect(twoTwoSoles())
eval @inspect(@run(twoTwoSoles()))

Development

npm install          # Install dependencies
npm run build        # Compile `src/` to `lib/`
npm run build:watch  # Watch the compilation
npm run test         # Run test

References

Papers:

Books:

Community

GitHub:

Telegram:

Contributions

To make a contribution, fork this project and create a pull request.

Please read the STYLE-GUIDE.md before you change the code.

Remember to add yourself to AUTHORS. Your line belongs to you, you can write a little introduction to yourself but not too long.

License

GPLv3

0.1.30

8 months ago

0.1.31

8 months ago

0.1.32

8 months ago

0.1.10

9 months ago

0.1.33

8 months ago

0.1.11

9 months ago

0.1.34

8 months ago

0.1.35

8 months ago

0.1.13

9 months ago

0.1.36

8 months ago

0.1.14

9 months ago

0.1.15

9 months ago

0.1.27

8 months ago

0.1.28

8 months ago

0.1.29

8 months ago

0.1.20

8 months ago

0.1.21

8 months ago

0.1.22

8 months ago

0.1.23

8 months ago

0.1.24

8 months ago

0.1.25

8 months ago

0.1.26

8 months ago

0.1.0

9 months ago

0.1.16

9 months ago

0.1.8

9 months ago

0.1.17

9 months ago

0.1.7

9 months ago

0.1.18

9 months ago

0.1.19

8 months ago

0.1.9

9 months ago

0.1.4

9 months ago

0.1.3

9 months ago

0.1.6

9 months ago

0.1.5

9 months ago

0.0.12

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.9

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago