Dart port of FormCoreJS: A minimal pure functional language based on self dependent types.

Overview

FormCore.js port to Dart.

So far only the parser and typechecker have been ported i.e. the FormCore.js file in the original repo.

(Original readme from https://github.com/moonad/FormCoreJS)

FormCoreJS

A pure JavaScript, dependency-free, 700-LOC implementation of FormCore, a minimal proof language featuring inductive reasoning. It is the kernel of Kind. It compiles to ultra-fast JavaScript and Haskell. Other back-ends coming soon.

Usage

Install with npm i -g formcore-js. Type fmc -h to see the available commands.

  • fmc file.fmc: checks all types in file.fmc

  • fmc file.fmc --js main: compiles main on file.fmc to JavaScript

As a library:

var {fmc} = require("formcore-js");
fmc.report(`
  id : @(A: *) @(x: A) A = #A #x x;
`);

What is FormCore?

FormCore is a minimal pure functional language based on self dependent types. It is, essentially, the simplest language capable of theorem proving via inductive reasoning. Its syntax is simple:

ctr syntax description
all @self(name: xtyp) rtyp function type
all %self(name: xtyp) rtyp like all, erased before compile
lam #var body pure, curried, anonymous, function
app (func argm) applies a lam to an argument
let !x = expr; body local definition
def $x = expr; body like let, erased before check/compile
ann {term : type} inline type annotation
nat +decimal natural number, unrolls to lambdas
chr 'x' UTF-16 character, unrolls to lambdas
str "content" UTF-16 string, unrolls to lambdas

It has two main uses:

A minimal, auditable proof kernel

Proof assistants are used to verify software correctness, but who verifies the verifier? With FormCore, proofs in complex languages like Kind can be compiled to a minimal core and checked again, protecting against bugs on the proof language itself. As for FormCore itself, since it is very small, it can be audited manually by humans, ending the loop.

An intermediate format for functional compilation

FormCore can be used as an common intermediate format which other functional languages can target, in order to be transpiled to other languages. FormCore's purity and rich type information allows one to recover efficient programs from it. Right now, we use FormCore to compile Kind to JavaScript, but other source and target languages could be involved.

The JavaScript Compiler

This implementation includes a high-quality compiler from FormCore to JavaScript. That compiler uses type information to convert highly functional code into efficient JavaScript. For example, the compiler will convert these λ-encodings to native representations:

Kind JavaScript
Unit Number
Bool Bool
Nat BigInt
U8 Number
U16 Number
U32 Number
I32 Number
U64 BigInt
String String
Bits String

Moreover, it will also convert any suitable user-defined self-encoded datatype to trees of native objects, using switch to pattern-match. It will also swap known functions like Nat.mul to native *, String.concat to native + and so on. It also performs tail-call optimization and inlines certain functions, including converting List.for to inline loops, for example. The generated JS should be as fast as hand-written code in most cases.

Example

The program uses self dependent datatypes to implement booleans, propositional equality, the boolean negation function, and proves that double negation is the identity (∀ (b: Bool) -> not(not(b)) == b):

Bool : * =
  %self(P: @(self: Bool) *)
  @(true: (P true))
  @(false: (P false))
  (P self);

true : Bool =
  #P #t #f t;

false : Bool =
  #P #t #f f;

not : @(x: Bool) Bool =
  #x (((x #self Bool) false) true);

Equal : @(A: *) @(a: A) @(b: A) * =
  #A #a #b
  %self(P: @(b: A) @(self: (((Equal A) a) b)) *)
  @(refl: ((P a) ((refl A) a)))
  ((P b) self);

refl : %(A: *) %(a: A) (((Equal A) a) a) =
  #A #x #P #refl refl;

double_negation_theorem : @(b: Bool) (((Equal Bool) (not (not b))) b) =
  #b (((b #self (((Equal Bool) (not (not self))) self))
    ((refl Bool) true))
    ((refl Bool) false));

main : Bool =
  (not false);

It is equivalent to this Kind snippet:

// The boolean type
type Bool {
  true,
  false,
}

// Propositional equality
type Equal <A: Type> (a: A) ~ (b: A) {
  refl ~ (b: a)
}

// Boolean negation
not(b: Bool): Bool
  case b {
    true: false,
    false: true,
  }

// Proof that double negation is identity
theorem(b: Bool): Equal(Bool, not(not(b)), b)
  case b {
    true: refl
    false: refl
  }!
You might also like...

Ruqe brings the convenient types and methods found in Rust into Dart, such as the Result, Option, pattern-matching, etc.

ruqe Ruqe brings the convenient types and methods found in Rust into Dart, such as the Result, Option, pattern-matching, etc. Additionally, the librar

Dec 28, 2022

Flutter Faux Self App Naked Eye 3D Effect

Flutter Faux Self App Naked Eye 3D Effect

Flutter Faux Self App Naked Eye 3D Effect

Jan 9, 2023

A self-hosted controller for mobile and macOS built using the Flutter framework.

A self-hosted controller for mobile and macOS built using the Flutter framework.

LunaSea LunaSea is a fully featured, open source self-hosted controller! Focused on giving you a seamless experience between all of your self-hosted m

Jan 2, 2023

A beautiful 😍 covid-19 app with self - assessment and more.

A beautiful 😍 covid-19 app with self - assessment and more.

Aarogya Seva Made with 🔥 in India 😍 Aarogya Seva is an Indian app developed using flutter for tracking live Covid-19 cases. App provides Coronavirus

Nov 25, 2022

Immich - Self-hosted Photo backup solution directly from your mobile phone

IMMICH Self-hosted Photo backup solution directly from your mobile phone. Note T

Dec 31, 2022

This is a Clone FinkuApp Inspired by This Real App It Self, Finku is a Money Management Tracker Develop by Fintech

This is a Clone FinkuApp Inspired by This Real App It Self, Finku is a Money Management Tracker Develop by Fintech

📦 Finku App This is a Clone FinkuApp Inspired by This Real App It Self, Finku is a Money Management Tracker Develop by Fintech. 🎖 Installing depende

Dec 16, 2022

Let's deliver Flutter app using Fastlane and self-hosted runner.

Let's deliver Flutter app using Fastlane and self-hosted runner.

Flutter CICD - Let's deliver app using Fastlane and Github selfhosted runner About This project shows how to create a minimal configuration for buildi

Nov 17, 2022

(Full-stack) Fully functional social media app (Instagram clone) written in flutter and dart with backend node.js and Postgres SQL.

(Full-stack) Fully functional social media app (Instagram clone) written in flutter and dart with backend node.js and Postgres SQL.

Photoarc A Fully functional social media app written in flutter and dart using node.js and Postgres SQL as backend. Backend Repository Demo Download t

Jan 5, 2023

Functional extensions to Dart collections.

collection_ext A set of extension methods for Dart collections, designed for the purpose of making it easier to write concise, functional-programming-

Nov 21, 2022
Owner
Modestas Valauskas
Dart & Flutter
Modestas Valauskas
Flutter language pickers2 - Language pickers package for Dart and Flutter

language_pickers2 Notes: Original repository from github.com/gomgom, unfortunate

Charles Dyason 0 Feb 6, 2022
FIDL(Flutter Interface Definition Language) is a language for transfer objects cross platforms.

Flutter Interface Definition Language (FIDL) README in English(TODO) FIDL 即 Flutter 接口定义语言,类似于AIDL(Android Interface Definition Language)。您可以利用它定义不同平台

null 47 Dec 7, 2022
null 1 Jan 8, 2022
Radiance - Dart port of gdx-ai

⚠️ This package is currently under development. This library is a collection of AI algorithms used in games. This includes: Steering behaviors (NYI) F

Flame Engine 20 Oct 30, 2022
A port of kotlin-stdlib for Dart/Flutter including immutable collections (KtList, KtMap, KtSet) and other packages

kt.dart This project is a port of Kotlin's Kotlin Standard library for Dart/Flutter projects. It's a useful addition to dart:core and includes collect

Pascal Welsch 460 Jan 9, 2023
A dart port of the excellent Guard Clauses C# package by Ardalis

Guard Clauses A dart port of the excellent C# Guard Clauses package by Ardalis. A simple extensible package with guard clause extensions. A guard clau

Chris Hibler 1 Apr 15, 2022
Flutter Navigation - all types of navigation in flutter run main.tabBar.dart to see tabBar, and run main.dart to see the otheres

pop_up_bar A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if th

Michael Odumosu 0 Jan 1, 2022
A simple set of terminal-based arcade games written in pure Dart.

dartcade A simple set of terminal-based arcade games written in pure Dart. Purpose I was developing some simple 2D UI libraries (such as package:gridd

Matan Lurey 7 Dec 7, 2022
A streaming client for the Komga self-hosted comics/manga/BD server targeting Android/iOS written in Dart/Flutter

Klutter A streaming client for the Komga self-hosted comics/manga/BD server targeting Android/iOS written in Dart/Flutter Background This is a project

Mark Winckle 58 Dec 7, 2022