{"id":19681950,"url":"https://github.com/higherorderco/formcorejs","last_synced_at":"2025-04-29T05:30:23.927Z","repository":{"id":40393650,"uuid":"312647962","full_name":"HigherOrderCO/FormCoreJS","owner":"HigherOrderCO","description":"A minimal pure functional language based on self dependent types.","archived":false,"fork":false,"pushed_at":"2022-05-11T08:27:46.000Z","size":797,"stargazers_count":72,"open_issues_count":3,"forks_count":13,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-28T14:18:11.658Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HigherOrderCO.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-13T17:58:23.000Z","updated_at":"2024-05-27T14:10:50.000Z","dependencies_parsed_at":"2022-08-09T19:10:28.379Z","dependency_job_id":null,"html_url":"https://github.com/HigherOrderCO/FormCoreJS","commit_stats":null,"previous_names":["moonad/formcorejs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HigherOrderCO%2FFormCoreJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HigherOrderCO%2FFormCoreJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HigherOrderCO%2FFormCoreJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HigherOrderCO%2FFormCoreJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HigherOrderCO","download_url":"https://codeload.github.com/HigherOrderCO/FormCoreJS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251444030,"owners_count":21590402,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T18:09:11.978Z","updated_at":"2025-04-29T05:30:23.551Z","avatar_url":"https://github.com/HigherOrderCO.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"FormCoreJS\n==========\n\nA pure JavaScript, dependency-free, 700-LOC implementation of FormCore, a minimal proof language featuring inductive reasoning. It is the kernel of [Kind](https://github.com/uwu-tech/Kind). It compiles to ultra-fast JavaScript and Haskell. Other back-ends coming soon.\n\nUsage\n-----\n\nInstall with `npm i -g formcore-js`. Type `fmc -h` to see the available commands.\n\n- `fmc file.fmc`: checks all types in `file.fmc`\n\n- `fmc file.fmc --js main`: compiles `main` on `file.fmc` to JavaScript\n\nAs a library:\n\n```\nvar {fmc} = require(\"formcore-js\");\nfmc.report(`\n  id : @(A: *) @(x: A) A = #A #x x;\n`);\n```\n\nWhat is FormCore?\n-----------------\n\nFormCore is a minimal pure functional language based on self dependent types.\nIt is, essentially, the simplest language capable of theorem proving via\ninductive reasoning. Its syntax is simple:\n\nctr  | syntax                   | description\n---- | ------------------------ | -----------\nall  | `@self(name: xtyp) rtyp` | function type\nall  | `%self(name: xtyp) rtyp` | like all, erased before compile\nlam  | `#var body`              | pure, curried, anonymous, function\napp  | `(func argm)`            | applies a lam to an argument\nlet  | `!x = expr; body`        | local definition\ndef  | `$x = expr; body`        | like let, erased before check/compile\nann  | `{term : type}`          | inline type annotation\nnat  | `+decimal`               | natural number, unrolls to lambdas\nchr  | `'x'`                    | UTF-16 character, unrolls to lambdas\nstr  | `\"content\"`              | UTF-16 string, unrolls to lambdas\n\nIt has two main uses:\n\n### A minimal, auditable proof kernel\n\nProof assistants are used to verify software correctness, but who verifies the\nverifier? With FormCore, proofs in complex languages like [Kind](https://github.com/uwu-tech/Kind)\ncan be compiled to a minimal core and checked again, protecting against bugs on\nthe proof language itself. As for FormCore itself, since it is very small, it\ncan be audited manually by humans, ending the loop.\n\n### An intermediate format for functional compilation\n\nFormCore can be used as an common intermediate format which other functional\nlanguages can target, in order to be transpiled to other languages. FormCore's\npurity and rich type information allows one to recover efficient programs from\nit. Right now, we use FormCore to compile [Kind](https://github.com/uwu-tech/Kind)\nto JavaScript, but other source and target languages could be involved.\n\nThe JavaScript Compiler\n------------------------\n\nThis implementation includes a high-quality compiler from FormCore to\nJavaScript. That compiler uses type information to convert highly functional\ncode into efficient JavaScript. For example, the compiler will convert these\nλ-encodings to native representations:\n\nKind | JavaScript\n--------- | ----------\nUnit      | Number\nBool      | Bool\nNat       | BigInt\nU8        | Number\nU16       | Number\nU32       | Number\nI32       | Number\nU64       | BigInt\nString    | String\nBits      | String\n\nMoreover, it will also convert any suitable user-defined self-encoded datatype\nto trees of native objects, using `switch` to pattern-match. It will also swap\nknown functions like `Nat.mul` to native `*`, `String.concat` to native `+` and\nso on. It also performs tail-call optimization and inlines certain functions,\nincluding converting `List.for` to inline loops, for example. The generated JS\nshould be as fast as hand-written code in most cases.\n\nExample\n-------\n\nThe program uses self dependent datatypes to implement booleans, propositional\nequality, the boolean negation function, and proves that double negation is the\nidentity (`∀ (b: Bool) -\u003e not(not(b)) == b`):\n\n```c\nBool : * =\n  %self(P: @(self: Bool) *)\n  @(true: (P true))\n  @(false: (P false))\n  (P self);\n\ntrue : Bool =\n  #P #t #f t;\n\nfalse : Bool =\n  #P #t #f f;\n\nnot : @(x: Bool) Bool =\n  #x (((x #self Bool) false) true);\n\nEqual : @(A: *) @(a: A) @(b: A) * =\n  #A #a #b\n  %self(P: @(b: A) @(self: (((Equal A) a) b)) *)\n  @(refl: ((P a) ((refl A) a)))\n  ((P b) self);\n\nrefl : %(A: *) %(a: A) (((Equal A) a) a) =\n  #A #x #P #refl refl;\n\ndouble_negation_theorem : @(b: Bool) (((Equal Bool) (not (not b))) b) =\n  #b (((b #self (((Equal Bool) (not (not self))) self))\n    ((refl Bool) true))\n    ((refl Bool) false));\n\nmain : Bool =\n  (not false);\n```\n\nIt is equivalent to this [Kind](https://github.com/uwu-tech/Kind)\nsnippet:\n\n```c\n// The boolean type\ntype Bool {\n  true,\n  false,\n}\n\n// Propositional equality\ntype Equal \u003cA: Type\u003e (a: A) ~ (b: A) {\n  refl ~ (b: a)\n}\n\n// Boolean negation\nnot(b: Bool): Bool\n  case b {\n    true: false,\n    false: true,\n  }\n\n// Proof that double negation is identity\ntheorem(b: Bool): Equal(Bool, not(not(b)), b)\n  case b {\n    true: refl\n    false: refl\n  }!\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhigherorderco%2Fformcorejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhigherorderco%2Fformcorejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhigherorderco%2Fformcorejs/lists"}